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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!