mips로 피보나치 짜려는데..

farland90의 이미지

피보나치의 리턴값을 배열에 저장하려고 하는데요..
명령어도 잘모르고 해서..여기저기 찾아보면서 짜고있는데..
뭐가 잘못된걸까요 ㅠ
지금은
li 0($t1), $v0 #save retrun value
여기서 에러가 나내요 ㅠㅠ

아시는 분들 계시면 도와주세요ㅠㅠㅠㅠ

=================================================================
#int main(){
# int fibo[20];
# int i;
#
# for(i=0;i<20;i++){ fibo[i]=fib(i+1);}
#
# for(i=0;i<20;i++) printf("%d ",fibo[i]);
#
# return 0; }
#
#int fib(int n) {
# if (n < 2) return n;
# else return fib(n-1) + fib(n-2); }

.text # put code into text segment
.globl __start # declare label main global to be accessible from other files

main:

subu $sp,$sp,32 # stack frame is 32 bytes long, min length 24
# here we use it to store only $fp, $ra, and $a0
sw $fp,16($sp) # save old frame pointer, after $a0-$a3
sw $ra,20($sp) # save return address in $ra
addu $fp,$sp,28 # set up frame pointer to the 1st word in frame

la $t3, list # put address of list into $t3
li $t2, 0 #t1 is index

loop1:
add $t1, $t3, $t2 #t1 is array pointer
addi $a0, $t2, 1 #argument
jal fib

li 0($t1), $v0 #save retrun value

addi $t2, $t2, 4 #move index

ble $a0,20,loop1


lw $ra,20($sp) # restore return address
lw $fp,16($sp) # restore frame pointer
addu $sp,$sp,32 # pop stack frame - clean frame
jr $ra # end of program, return to system




.text
fib:
subu $sp,$sp,32 # same thing with frame preparation
sw $ra,20($sp)
sw $fp,16($sp)
addu $fp,$sp,28
sw $a0,0($fp) # save factorial argument (n)

lw $v0,0($fp) # load n - kept in $a0 saved on stack
bl $v0,2,$L1 # branch if n<2

subu $a0,$a0,1
jal fib

add $s1,$zero,$v0 #s1=fib(y-1)

subu $a0,$s0,2
jal fib #v0=fib(n-2)

addi $v0,$v0,$s1 #v0=fib(n-2)+$s1

$L1: # result is in $v0
lw $ra,20($sp) # restore $ra
lw $fp,16($sp) # restore $fp
addu $sp,$sp,32 # pop stack
j $ra # return to caller

list: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.