Question: starting from the MIPS code below that preforms multiplication, I am trying to produce a new function that performs an unsigned integer divide in MIPS

starting from the MIPS code below that preforms multiplication, I am trying to produce a new function that performs an unsigned integer divide in MIPS assembly code. The first number entered is assumed to be the dividend (numerator), the second the divisor. It can be assumed that both numbers will fit into 16 or fewer bits and both are positive. can you help implementing

.data

prompt: .asciiz "Enter a number: "

.align 2 saven:

.word

.text

la $a0, prompt

li $v0, 4

syscall

li $v0, 5

syscall

sw $v0, saven($0)

la $a0, prompt

li $v0, 4

syscall

li $v0, 5

syscall

move $a1, $v0 # move integer as 2nd arg

lw $a0, saven($0)

jal multiply

move $a0, $v0 # put answer into syscall arg

li $v0, 1 # syscall: print integer

syscall

li $v0, 10

syscall

multiply:

move $v0, $0 # start product (result) at zero

li $t0, 16 # number of bits to multiply

mloop:

andi $t1, $a0, 1 # get least significant bit of multiplier

beq $t1, $0, dontadd # if zero, skip adding in multiplicand

add $v0, $v0, $a1 # add multiplicand to the product

dontadd:

subi $t0, $t0, 1 # decrement bit counter

srl $a0, $a0, 1 # shift multiplier right (see next bit)

sll $a1, $a1, 1 # multiplying multiplier by 2

bne $t0, $0, mloop # if there are more bits, loop

jr $ra

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!