0

请帮助我,我根据计算机组织和设计书中的算法编写了代码 mips 来划分 2 符号整数,但结果并不像我预期的那样。我不知道我错了什么:

.text
.globl main

main:

ori $s0,0x00000007  #set value dividend
ori $s1,0x00000002  #set value divisor
ori $v0,0x00000000  #set value quotient
ori $v1,0x00000000  #set value remander
ori $t2,0x00000000  #set value count
start:

sub $v1,$v1,$s1 #Subtract the Divisor register from the Remainder register and place the result in the Remainder register
slt $t1,$v1,$zero #Remainder < 0 jump to loop 2b
beqz $t1,loop2a #else jump to loop 2a
j loop2b    
loop2a:

#Shift the Quotient register to the left, setting the new rightmost bit to 1
sll $v0,$v0,1
addi $v0,$v0,1
srl $s0,$s0,1
addi $t2,$t2,1  #increase count to 1
slti $t1,$t2,33 #if count < 33 repetitions then continue to start else done
beqz $t1,done   
j start
loop2b:

#Restore the original value by adding the Divisor register to the Remainder register and place the sum in the 
#Remainder register. Also shift the Quotient register to the left, setting the new least significant bit to 0.
add $v1,$s0,$v1
sll $v0,$v0,1
addi $v0,$v0,0
addi $t2,$t2,1  #increase count to 1
slti $t1,$t2,33 #if count < 33 repetitions then continue to start else done
beqz $t1,done
j start
done:

#display the result
addi $a0,$v0,0
li $v0,1
syscall
addi $a0,$v1,0
li $v0,1
syscall
li $v0,10
syscall
4

0 回答 0