我试图在程序集中编写一个程序,它将充当使用递归循环的复合兴趣计数器。我能够让程序使用设置的Principal并设置利率并且迭代10次,在每次迭代后显示平衡。现在我正在尝试更改,因此它要求用户提供起始本金,利率和目标本金。然后程序需要迭代直到满足目标主体。
到目前为止,这是我的非工作代码。我想我搞乱了我正在使用的寄存器。我尝试将这些在beq线上使用的寄存器更改为$ a2和$ a0,但这也没有用。有什么建议? Idk如果我很近或离开。我很难跟上register = /
promptFirst: .asciiz "Enter Your Starting Balance: \n"
promptSecond: .asciiz "Enter the Interst Rate: \n"
promptThird: .asciiz "Enter Your Target Balance \n"
promptNow: .asciiz "\nYour Balance After A Iteration:\n"
.text
.globl main
main:
# Prints the first prompt
li $v0, 4 # syscall number 4 will print string whose address is in $a0
la $a0, promptFirst # "load address" of the string
syscall # actually print the string
# Reads in the first operand
li $v0, 5 # syscall number 5 will read an int
syscall # actually read the int
move $s0, $v0 # save result in $s0 for later
# Prints the second prompt
li $v0, 4 # syscall number 4 will print string whose address is in $a0
la $a0, promptSecond # "load address" of the string
syscall # actually print the string
# Reads in the second operand
li $v0, 5 # syscall number 5 will read an int
syscall # actually read the int
move $s1, $v0 # save result in $s1 for later
# Prints the third prompt
li $v0, 4 # syscall number 4 will print string whose address is in $a0
la $a0, promptThird # "load address" of the string
syscall # actually print the string
# Reads in the third operand
li $v0, 5 # syscall number 5 will read an int
syscall # actually read the int
move $s2, $v0 # save result in $s2 for later
jal LOOP
ENDLOOP:
j EXIT
LOOP:
la $a0, $s0 # load the address of the principal
la $a1, $s1 # load the address of the interest
la $a2, $s2 # load the address of the goal principal
lwc1 $f2, ($a0) # load the principal
lwc1 $f4, ($a1) # load the interest rate
lwc1 $f6 ($a2)
mul.s $f12, $f4, $f2 # calculate the balance
swc1 $f12, ($a0)
li $v0, 4 # syscall number 4 will print string whose address is in $a0
la $a0, promptNow # "load address" of the string
syscall # actually print the string
li $v0, 2 # system call #2
syscall
addi $sp,$sp,-4 # push the current return address
sw $ra,($sp)
beq $f12, $f6, LOOPRET
beq $f12, $f6, ENDLOOP
jal LOOP
LOOPRET:
lw $ra,($sp) # pop the saved return address
addi $sp,$sp,4
jr $ra
EXIT:
jr $ra
任何建议都会很好。对于我需要做的问题还有很多。但我需要首先完成这一部分。我觉得我已经筋疲力尽了
答案 0 :(得分:0)
la $a0, $s0 # load the address of the principal
这甚至可以编译吗? la
的目的是[L]或标签的[A]地址。您无法获取注册地址。
lwc1 $f2, ($a0) # load the principal
将$a0
中的错误值放在一边,lwc1
不执行任何类型的整数到浮点转换。所以你不能通过这样做得到适当的浮动。
你可能应该做的是废弃la
/ lwc1
指令,而是使用类似的内容:
mtc1 $s0,$f2 # move $s0 to floating point register $f2
cvt.s.w $f2,$f2 # convert the integer in $f2 to a float
# ..similarly for the rest of your values