- 论坛徽章:
- 0
|
code3code1的非连续x)
int f(int x)
{
int y;
switch(x) {
case 0:
y=8;
break;
case 88:
y=6;
break;
case 111:
y=7;
break;
case 211:
y=4;
break;
case 333:
y=11;
break;
case 555:
y=12;
break;
case 688:
y=88;
break;
default:
y=x*x;
break;
};
return(y);
}
int main()
{
int x,y;
x=11;
y=f(x);
return(0);
}
对应的asm:
.file "test3.cpp"
.text
.align 2
.globl _Z1fi
.type _Z1fi,@function
_Z1fi:
.LFB9:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $8, %esp
.LCFI2:
movl 8(%ebp), %eax
movl %eax, -8(%ebp)
cmpl $211, -8(%ebp)
je .L6
cmpl $211, -8(%ebp)
jg .L12
cmpl $88, -8(%ebp)
je .L4
cmpl $88, -8(%ebp)
jg .L13
cmpl $0, -8(%ebp)
je .L3
jmp .L10
.L13:
cmpl $111, -8(%ebp)
je .L5
jmp .L10
.L12:
cmpl $555, -8(%ebp)
je .L8
cmpl $555, -8(%ebp)
jg .L14
cmpl $333, -8(%ebp)
je .L7
jmp .L10
.L14:
cmpl $688, -8(%ebp)
je .L9
jmp .L10
.L3:
movl $8, -4(%ebp)
jmp .L2
.L4:
movl $6, -4(%ebp)
jmp .L2
.L5:
movl $7, -4(%ebp)
jmp .L2
.L6:
movl $4, -4(%ebp)
jmp .L2
.L7:
movl $11, -4(%ebp)
jmp .L2
.L8:
movl $12, -4(%ebp)
jmp .L2
.L9:
movl $88, -4(%ebp)
jmp .L2
.L10:
movl 8(%ebp), %eax
imull 8(%ebp), %eax
movl %eax, -4(%ebp)
.L2:
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)" |
|