Question: I have written the following program according to the attached image. With my testing, I believe the issue with the program is in the subtraction
I have written the following program according to the attached image. With my testing, I believe the issue with the program is in the subtraction in Step Please help me with getting the subtraction to work correctly, as I believe that it is the only thing holding this program back from working correctly.
data
prompt: asciiz "Enter Dividend:
prompt: asciiz
Enter Divisor:
ans: asciiz
Quotient:
ans: asciiz
Remainder:
text
globl main
main:
# print prompt
la $a prompt
li $v
syscall
# take in dividend
li $v
syscall
# place in remainder reg
li $t
move, $t $v
# print prompt
la $a prompt
li $v
syscall
# take in divisor
li $v
syscall
move $t $v
li $t
# initialize quotient reg
li $t
# initialize loop counter
li $t
Step:
addi $t $t # decrement loop counter
#sub $t $t $t # subtract remainder by divisor
#sub $t $t $t
subu $t $t $t
sltu $t $t $t
subu $t $t $t
bltz $t Stepb
Stepa:
sll $t $t # shift quotient
ori $t $t # set LSB to
j Step
Stepb:
add $t $t $t # rem rem div
sll $t $t # shift quotient
Step:
andi $t $t # extract LSB of left divisor
sll $t $t # shift bit to MSB
srl $t $t # shift left divisor left
srl $t $t # shift right divisor left
or $t $t $t # set MSB of right divisor
bnez $t Step
Done:
# print ans
la $a ans
li $v
syscall
# print quotient
move $a $t
li $v
syscall
# print ans
la $a ans
li $v
syscall
# print remainder
move $a $t
li $v
syscall
li $v
syscall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
