Assembly 汇编程序问题

Assembly 汇编程序问题,assembly,recursion,calculator,Assembly,Recursion,Calculator,我试图在汇编中编写一个程序,它将充当使用递归循环的复利计数器。我能够让程序在设定本金和设定利率的情况下运行,它迭代了10次,每次迭代后显示余额。现在我试图更改它,因此它要求用户输入起始本金、利率和目标本金。然后,程序需要迭代,直到满足目标主体 这是到目前为止我的非工作代码。我想我弄乱了我正在使用的寄存器。Iv尝试将beq线路上使用的该寄存器更改为$a2和$a0,但这也不起作用。有什么建议吗?Idk如果我接近或远离。我很难跟上节奏=/ promptFirst: .asciiz "En

我试图在汇编中编写一个程序,它将充当使用递归循环的复利计数器。我能够让程序在设定本金和设定利率的情况下运行,它迭代了10次,每次迭代后显示余额。现在我试图更改它,因此它要求用户输入起始本金、利率和目标本金。然后,程序需要迭代,直到满足目标主体

这是到目前为止我的非工作代码。我想我弄乱了我正在使用的寄存器。Iv尝试将beq线路上使用的该寄存器更改为$a2和$a0,但这也不起作用。有什么建议吗?Idk如果我接近或远离。我很难跟上节奏=/

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
任何建议都很好。这个问题还有很多我需要做的。但我需要先完成这部分。我觉得我好像已经精疲力竭了

la  $a0, $s0    # load the address of the principal
这甚至可以编译吗?
la
的目的是加载标签的[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

谢谢,我对汇编编程真的很陌生。我使用la指令的原因是因为我加载了一个.float变量,我声明它为PRINCIPAL,它=100。我用了(la$a0,本金)。我在设置递归时做了这部分工作。我猜我假设主体部分只是一个容纳100的内存位置。所以我的想法是用用户输入主体的记忆位置来代替它。但我想我错了=这太令人困惑了。现在很晚了。我明天会检查你的解决方案。我真的很感谢你的回复。非常感谢。我试着帮你修好。我通过了那个编译错误。但现在,我得到了一个编译错误的beq函数调用。有浮点beq吗?非常感谢!我还在努力。我还没完全明白。