尽管我尝试输入不同的值,但是Qtspim仍然打印出值“ 0”,并且输入也没有保存在寄存器中,我尝试在Internet上找到答案,但是似乎没人之前面对这个问题。我工作了4个小时,对此感到非常沮丧。 这是我的代码,我尝试定义输入是否为素数。
# Power program
# ----------------------------------
# Data Segment
.data
request: .asciiz "Enter an integer:"
Yes: .asciiz " is a prime number.\n"
No: .asciiz " is not a prime number\n."
End: .asciiz"End!\n"
Key: .word -1
One: .word 1
# ----------------------------------
# Text/Code Segment
.text
.globl main
main:
lw $t1,One
add $s2,$zero,$zero
lw $s3,One
lw $s0,Key
add $s5,$zero,$zero
j power # call the function power
li $v0, 10 # call code for exit
syscall # system call
.end main
.globl power
power:
j power_loop
power_loop:
la $a0, request # load string request in memory to $a0
li $v0, 4 # print out the string
syscall #prevent Memory address out of bounds
li $v0, 5
syscall
move $s7,$v0
beq $s7, $s0, exit_L #when input =-1 exit
j Prime #otherwise go to define the input whether prime num
Prime:
beq $s7,$t1,result
div $s7,$t1
mthi $t4
beq $t4,$zero,count
addi $t1,$t1,1
j Prime
count: #counting the number of factors
addi $s2,1
addi $t1,$t1,1
result: addi $t1,$zero,1
bne $s2,$s3,resultNo
beq $s2,$s3,resultYes
resultYes: li $v0,1
move $a0,$s7
syscall
add $s2,$zero,$zero
la $a0,Yes
li $v0,4
syscall
j power_loop
resultNo: li $v0,1
move $a0,$s7
syscall
add $s2,$zero,$zero
la $a0,No
li $v0,4
syscall
j power_loop
exit_L:
la $a0,End
li $v0,4
syscall
jr $ra
.end power