我需要編寫一個迭代10次的程序。每次它將更新一個值並將其打印到屏幕上。彙編程序:遞歸?
我知道必須做一些事情來創建一個堆棧並保存該值,以便它可以迭代回到正確的部分並繼續執行該程序。伊夫嘗試了很多東西,但我無法弄清楚。這是到目前爲止我的代碼
# ############################################################### #
# Phase2.ASM #
# #
# This program will recurse 10 times and show how much interest #
# is made after 10 "months" #
# #
# ############################################################### #
.data
PRINCIPAL: .float 100.0 # principal = $100.00
INTEREST_RATE: .float 0.012 # interest = 1.2%
promptFirst: .asciiz "Your starting Principal is $100.00: \n"
promptSecond: .asciiz "Your interest rate is 1.2%: \n"
promptNow: .asciiz "Interest Made After a Month:\n"
.text
.globl main
main:
First:
# 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
Second:
# 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
jal CI
j EXIT
CI:
la $a0, PRINCIPAL # load the address of the principal
la $a1, INTEREST_RATE # load the address of the principal
lwc1 $f2, ($a0) # load the principal
lwc1 $f4, ($a1) # load the interest rate
mul.s $f12, $f4, $f2 # calculate the balance
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
jr $ra
EXIT:
jr $ra
# END OF THE LINES ###############################################
我的電流輸出至今:
你開始主要爲$ 100.00:
你的利率是1.2%:
利息款後一個月:
1.20000005
Aany help would rea值得讚賞。彙編編程真的很糟糕。
PS:轉讓已被通過遞歸
編輯完成了!新規範
# ############################################################### #
# Phase2.ASM #
# #
# This program will recurse 10 times and show how much interest #
# is made after 10 "months" #
# #
# ############################################################### #
.data
PRINCIPAL: .float 100.0 # principal = $100.00
INTEREST_RATE: .float 1.012 # interest = 1.2%
promptFirst: .asciiz "Your starting Principal is $100.00: \n"
promptSecond: .asciiz "Your interest rate is 1.2%: \n"
promptNow: .asciiz "\nYour Balance After A Month:\n"
.text
.globl main
main:
First:
# 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
Second:
# 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
li $t1, 0
jal CI
ENDCI:
j EXIT
CI:
add $t1, $t1, 1
la $a0, PRINCIPAL # load the address of the principal
la $a1, INTEREST_RATE # load the address of the principal
lwc1 $f2, ($a0) # load the principal
lwc1 $f4, ($a1) # load the interest rate
mul.s $f12, $f4, $f2 # calculate the balance
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
beq $t1, 10, ENDCI
jal CI
jr $ra
EXIT:
jr $ra
# END OF THE LINES ###############################################
新的輸出:
我們的出發校長爲$ 100.00: 你的利率是1.2%:
您的餘額後一個月:
101.19999695
一個月後餘額:
101.19999695
您的餘額後一個月:
101.19999695
您的餘額後一個月:
101.19999695
您的餘額後一個月:
101.19999695
您的餘額後一個月:
101.19999695
您的餘額後一個月:
101.19999695
您的餘額後一個月:
101.19999695
你的平衡之後A月:
101。19999695
您的餘額後一個月:
101.19999695
所以我得到的代碼重複10次。我需要更新金額,以便顯示上個月+增加的利息
㈣嘗試了一些東西律。沒有什麼值得一提的。我有一些關於如何設置堆棧幀和幀指針的例子,但並不真正知道我在做什麼。 – CoffeePeddlerIntern 2013-03-11 03:06:52
我知道它現在迭代10次。但價值不更新。我真的不知道如何去浮點數,以及如何更新和保存它。 – CoffeePeddlerIntern 2013-03-11 03:08:03