コードはコンパイルされません。少し変更すると、MIPS シミュレーターを使用して Ubuntu で MIPS にコンパイルされます。
#include<stdio.h>
int fibnacci(int c)
{
if(c==0)
return 0;
else if(c==1)
return 1;
else
return (fibnacci(c-1)+fibnacci(c-2));
}
int main(){
int i;
int a;
printf("Enter the fib number");
scanf("%d",&i);
a= fibnacci(i);
printf("The value is %d",a);
}
アセンブリは
.file 1 "mips-c.c"
# -G value = 8, Cpu = 3000, ISA = 1
# GNU C version cygnus-2.7.2-970404 (mips-mips-ecoff) compiled by GNU C version cygnus-2.7.2-970404.
# options passed: -msoft-float
# options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
# -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker -msoft-float
# -meb -mcpu=3000
gcc2_compiled.:
__gnu_compiled_c:
.text
.align 2
.globl fibnacci
.ent fibnacci
fibnacci:
.frame $fp,32,$31 # vars= 0, regs= 3/0, args= 16, extra= 0
.mask 0xc0010000,-8
.fmask 0x00000000,0
subu $sp,$sp,32
sw $31,24($sp)
sw $fp,20($sp)
sw $16,16($sp)
move $fp,$sp
sw $4,32($fp)
lw $2,32($fp)
bne $2,$0,$L2
move $2,$0
j $L1
j $L3
$L2:
lw $2,32($fp)
li $3,1 # 0x00000001
bne $2,$3,$L4
li $2,1 # 0x00000001
j $L1
j $L5
$L4:
lw $3,32($fp)
addu $2,$3,-1
move $4,$2
jal fibnacci
move $16,$2
lw $3,32($fp)
addu $2,$3,-2
move $4,$2
jal fibnacci
addu $3,$16,$2
move $2,$3
j $L1
$L5:
$L3:
$L1:
move $sp,$fp # sp not trusted here
lw $31,24($sp)
lw $fp,20($sp)
lw $16,16($sp)
addu $sp,$sp,32
j $31
.end fibnacci
.rdata
.align 2
$LC0:
.ascii "Enter the fib number\000"
.sdata
.align 2
$LC1:
.ascii "%d\000"
.rdata
.align 2
$LC2:
.ascii "The value is %d\000"
.text
.align 2
.globl main
.ent main
main:
.frame $fp,32,$31 # vars= 8, regs= 2/0, args= 16, extra= 0
.mask 0xc0000000,-4
.fmask 0x00000000,0
subu $sp,$sp,32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
jal __main
la $4,$LC0
jal printf
la $4,$LC1
addu $5,$fp,16
jal scanf
lw $4,16($fp)
jal fibnacci
sw $2,20($fp)
la $4,$LC2
lw $5,20($fp)
jal printf
$L6:
move $sp,$fp # sp not trusted here
lw $31,28($sp)
lw $fp,24($sp)
addu $sp,$sp,32
j $31
.end main