Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of 1's in the given number. For example: 1111 0000 should return 4
j main
###############################################################
# Data Section
.data
#
new_line: .asciiz "\n"
space: .asciiz " "
double_range_lbl: .asciiz "\nDouble range (Decimal Values)
\nExpected output:\n1200 -690 104\nObtained output:\n"
swap_bits_lbl: .asciiz "\nSwap bits (Hexadecimal Values)\nExpected
output:\n75757575 FD5775DF 064B9A83\nObtained output:\n"
count_bits_lbl: .asciiz "\nCount bits \nExpected output:\n20 24
13\nObtained output:\n"
swap_bits_test_data: .word 0xBABABABA, 0xFEABBAEF,
0x09876543
swap_bits_expected_data: .word 0x75757575, 0xFD5775DF,
0x064B9A83
double_range_test_data: .word 945, -345, 0, -3, 55
double_range_expected_data: .word 1200, -6, 104
hex_digits: .byte '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
###############################################################
# Text Section
.text
# Utility function to print hexadecimal numbers
print_hex:
move $t0, $a0
li $t1, 8 # digits
lui $t2, 0xf000 # mask
mask_and_print:
# print last hex digit
and $t4, $t0, $t2
srl $t4, $t4, 28
la $t3, hex_digits
add $t3, $t3, $t4
lb $a0, 0($t3)
li $v0, 11
syscall
# shift 4 times
sll $t0, $t0, 4
addi $t1, $t1, -1
bgtz $t1, mask_and_print
exit:
jr $ra
###############################################################
###############################################################
###############################################################
# PART 1 (Count Bits)
#
# You are given an 32-bits integer stored in $t0. Count the number
of 1's
#in the given number. For example: 1111 0000 should return 4
count_bits:
move $t0, $a0
############################## Part 1: your code begins here
###
############################## Part 1: your code ends here
###
move $v0, $t0
jr $ra
PROGRAM:
.data
prompt: .asciiz "Enter a number: "
output: .asciiz "Number of 1's = "
.text
main:
# Prompt to the user to enter a number
li $v0,4
la $a0,prompt
syscall
# Reading input from user
li $v0,5
syscall
move $a0,$v0
# calling count_bits function
jal count_bits
# Storing the returned value in $t0
move $t0,$v0
# Displaying the output to the user
li $v0,4
la $a0,output
syscall
li $v0,1
move $a0,$t0
syscall
# Exiting the program
li $v0,10
syscall
# count_bits function
count_bits:
move $t0,$a0 # Moving
function argument to $t0
li $t1,0 # Count
variable
li $t3,32 # Loop
termination condition variable
again:
and $t2,$t0,1 #
Comparing LSB with 1
bne $t2,1,count # If
not equal branch to count label
addi $t1,$t1,1 # If
equal increment count variable value
count: srl $t0,$t0,1 #
Shift the input number by 1
addi $t3,$t3,-1 #
Decreasing the loop termination variable value by 1
bnez $t3,again # if
loop termination not zero continuing the counting process
move $v0,$t1 # Storing
the count value in $v0
jr $ra
# Returning back to the main function
Please refer to the screenshot of the program for indentation of code:
OUTPUT:
Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of...
WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4 la...
.data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a0, $v0 jal factorial # jump factorial and save position to $ra move $t0, $v0 # $t0 = $v0 # show prompt li $v0, 4 la $a0, result syscall # print the result li $v0, 1 # system call #1 - print int move $a0,...
what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:li $v0, 1l li $s0,0 la $s1, A li $t3, 0 loop: slti $t0, $s0, 17 beq: $t0, $zero, end sll $t1, $s0 2 add $t2 $s1 $t1 syscall addi $s0, $s0, 1 j loop end: li $v0, 1 add $a0, $zero, $t3 syscall
Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...
I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort. Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main: # la $t0, val # loads val into a register # li $t1, 0 #keeps track of how many numbers entered la $a0,...
.data A: .word 84 111 116 97 108 32 105 115 32 . text main:li $v0, 1l li $s0,0 la $s1, A li $t3, 0 loop: slti $t0, $s0, 17 beq: $t0, $zero, end sll $t1, $s0 2 add $t2 $s1 $t1 syscall addi $s0, $s0, 1 j loop end: li $v0, 1 add $a0, $zero, $t3 syscall /// whats the output of above assembly program
im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...
The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...
1. Modify larger.s to let the user to enter three numbers and output the largest value # larger.s-- prints the larger of two numbers specified # at runtime by the user. # Registers used: # $t0 - used to hold the first number. # $t1 - used to hold the second number. # $t2 - used to store the larger of $t1 and $t2. # $v0 - syscall parameter and return value. # $a0 - syscall parameter. .text main: ##...
In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted triangle. The height of the triangle will be given in $a0, and will be between 1 and 40 inclusive. For the first three tests, the included test harness should print (spimsimulator(dot)sourceforge(dot)net) 1. (25 pts.) In the SPIM simulator in MIPS assembly, write the itri routine in the itri.s skeleton to make it print an inverted trian- gle. The height...