2013-10-25 106 views
0

我的代碼拋出了一些錯誤,而且我總是不太熟悉MIPS語法。給定的問題是:使用Fibonacci序列的MIPS

1202年研究的最初問題是兔子在理想情況下能繁殖多快。

假設一對新出生的兔子,一男一女,放在田裏。

兔子一個月後性成熟,因此在第二個月結束時,雌性可產生另一對兔子。

假設我們的兔子不死,並且女性從第二個月開始每個月都會生產一對(一男一女)。

一年內會有多少雙?

我到目前爲止的代碼是:

.data 

str: .asciiz "The number of pairs of rabbits in a year are: " 

.text 
.globl main 

li $t0, 12 
li $t1, 0 
li $t2, 1 
li $t4, 0 

la $a0, str 
li $v0, 4 
syscall 

loop: 

beq $t4, $t0, exit 
move $t3, $t2 
add $t2, $t1, $t2 
move $t1, $t3 
addi $t4, $t4, 1 

j loop 

exit: 

move $a0, $t2 
li $v0, 1 
syscall 


li $v0, 10 
syscall 

回答

0

嘛,你不說是什麼錯誤......但是當我插入SPIM這個我收到:

SPIM Version 7.4 of January 1, 2009 
Copyright 1990-2004 by James R. Larus ([email protected]). 
All Rights Reserved. 
See the file README for a full copyright notice. 
Loaded: /opt/local/share/spim/exceptions.s 
The following symbols are undefined: 
main 

Instruction references undefined symbol at 0x00400014 
[0x00400014] 0x0c000000 jal 0x00000000 [main]   ; 180: jal main 

這意味着你缺少主標籤。你的主要功能前添加它:

.text 
.globl main 
main: 

li $t0, 12 
... 

這產生了預期的答案:

The number of pairs of rabbits in a year are: 233 
+0

我很抱歉。這是我的一個非常愚蠢的錯誤,但非常感謝你。 – user2213630

0

你應該在標籤的「設置」更改設置。 模擬器 - >設置 - > MIPS - >異常處理程序: 取消選中此選項「加載異常處理程序」 這樣您禁用本機MIPS代碼和您自己的代碼工作。