|
code2:
int f(int x)
{
int y;
if(x==0)
{
y=8;
}
else if(x==1)
{
y=6;
}
else if(x==2)
{
y=7;
}
else if(x==3)
{
y=4;
}
else if(x==4)
{
y=11;
}
else if(x==5)
{
y=12;
}
else if(x==6)
{
y=88;
}
else
{
y=x*x;
}
return(y);
}
int main()
{
int x,y;
x=11;
y=f(x);
return(0);
}
对应的asm:
.file "test2.cpp"
.text
.align 2
.globl _Z1fi
.type _Z1fi,@function
_Z1fi:
.LFB9:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $4, %esp
.LCFI2:
cmpl $0, 8(%ebp)
jne .L2
movl $8, -4(%ebp)
jmp .L3
.L2:
cmpl $1, 8(%ebp)
jne .L4
movl $6, -4(%ebp)
jmp .L3
.L4:
cmpl $2, 8(%ebp)
jne .L6
movl $7, -4(%ebp)
jmp .L3
.L6:
cmpl $3, 8(%ebp)
jne .L8
movl $4, -4(%ebp)
jmp .L3
.L8:
cmpl $4, 8(%ebp)
jne .L10
movl $11, -4(%ebp)
jmp .L3
.L10:
cmpl $5, 8(%ebp)
jne .L12
movl $12, -4(%ebp)
jmp .L3
.L12:
cmpl $6, 8(%ebp)
jne .L14
movl $88, -4(%ebp)
jmp .L3
.L14:
movl 8(%ebp), %eax
imull 8(%ebp), %eax
movl %eax, -4(%ebp)
.L3:
movl -4(%ebp), %eax
leave
ret
.LFE9:
.Lfe1:
.size _Z1fi,.Lfe1-_Z1fi
.align 2
.globl main
.type main,@function
main:
.LFB11:
pushl %ebp
.LCFI3:
movl %esp, %ebp
.LCFI4:
subl $8, %esp
.LCFI5:
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $11, -4(%ebp)
subl $12, %esp
pushl -4(%ebp)
.LCFI6:
call _Z1fi
addl $16, %esp
movl %eax, -8(%ebp)
movl $0, %eax
leave
ret
.LFE11:
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)"
|