Question
MIPS ASSEMBLY LANGUAGE Write MIPS code to convert binary to decimal : (01110001) 2 to (113) 10 .data binary_digit: .word 0 1 1 1 0
MIPS ASSEMBLY LANGUAGE
Write MIPS code to convert binary to decimal: (01110001)2 to (113)10
.data
binary_digit: .word 0 1 1 1 0 0 0 1 # is 113 in decimal
.globl main
main: # Load arguments to argument registers
# Call convert() # Print return value # (it's in $v0, make sure to copy it before overwriting to print) # Properly end program
convert:
# This label is where conversion of the current array will begin
# Arguments to "functions" in MIPS are passed in on $a# registers # in this case, $a0 = &array[0], $a1 = array.size() # zero the loop counter # zero the return register, i.e. running total
# beginning of loop # If counter >= size, we've iterated every digit and it's time to return the running total # Get bit at current index # Calculate power to raise the current bit to # Multiply current bit by 2^power using shift operation # (Calculate 2^power using multiply loop) # (Remember, sll $reg $reg 1 === $reg = $reg * 2) # Add current_bit * 2^power to running total # Increment index # Start loop again # end of loop
# Jump back to Return Address
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started