-1
我有這個家庭作業問題。如何將序列存儲在MIPS中的數組中?
編寫一個產生以下序列的程序; 1,2,2,4,8,32,256,...並將其存儲在一個數組中,具體取決於用戶選擇的術語數量。序列中的每個元素可以通過乘以它之前的兩個元素來計算。換句話說,通過公式Sn = Sn-1×Sn-2來計算第n個序列號Sn。
我試過,但它並沒有跑
我的代碼
^^
# UNTITLED PROGRAM
.data # Data declaration section
str1: .ascii "Please enter the number of terms to produce: "
arr: .space 40
.text
main: # Start of code section
li $v0, 4 # system call code for printing string = 4
la $a0, str1 # load address of string to be printed into $a0
syscall # call operating system to perform print operation
li $v0, 5 # get ready to read in integers
syscall # system waits for input
move $s0,$v0 # store the result of the read (returned in $v0) in num1
la $s1,arr
addi $t2,$zero,2 # i=2
addi $t0,$zero,1
add $t1,$t0,$t0
sw $t0,0($s1)
sw $t1,0($s1)
L1:
addi $t2,$t2,1 #i++
addi $s1,$s1,4
lw $t4,0($s1) #A[i-1]
lw $t5,4($s1)
mul $t3,$t4,$t5
sw $t3,8($s1)
beq $t2,$s0,print
j L1
print:
lw $t3,0($s1)
li $v0, 1 # system call code for print_int
move $a0, $t3 # integer to print
syscall # print it
addi $s1,$s1,4
beq $t2,$s0,Exit
j print
Exit:
li $v0, 10 # exits program
syscall
# END OF PROGRAM
你做了什麼調試工作?你認爲問題在哪裏? – 2012-04-15 22:35:48
請格式化您的代碼。 – blackcompe 2012-04-15 22:36:55
@MichaelPetrotta我用棧來保存結果然後在數組中排序..但是我的代碼沒有運行..最後,編碼程序__ for循環=> A [i] = A [i-1] * A [i -2] 我認爲問題如何從數組中加載字和排序字指令 – Dalal 2012-04-15 23:10:42