汇编包含C代码

25 篇文章 0 订阅
11 篇文章 0 订阅

反汇编的时候带上C代码便于观察

 

比较三元表达式和if else的差异

a1.c

#include <stdio.h>  

int main(void)  
{  
int a=1;
int b=2;
int c=0;
a = (b>c)?1:0;
return 0;
}


a2.c

#include <stdio.h>  

int main(void)  
{  
int a=1;
int b=2;
int c=0;
if(b>c)
{
a=1;
}
else
{
a=0;
}
return 0;
} 

 

编译

#gcc -g a1.c

反汇编

#objdump -dS a.out

#include <stdio.h>  

int main(void)  
{  
 8048394:       55                      push   %ebp
 8048395:       89 e5                   mov    %esp,%ebp
 8048397:       83 ec 10                sub    $0x10,%esp
int a=1;
 804839a:       c7 45 f4 01 00 00 00    movl   $0x1,-0xc(%ebp)
int b=2;
 80483a1:       c7 45 f8 02 00 00 00    movl   $0x2,-0x8(%ebp)
int c=0;
 80483a8:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%ebp)
a = (b>c)?1:0;
 80483af:       8b 45 f8                mov    -0x8(%ebp),%eax
 80483b2:       3b 45 fc                cmp    -0x4(%ebp),%eax
 80483b5:       0f 9f c0                setg   %al
 80483b8:       0f b6 c0                movzbl %al,%eax
 80483bb:       89 45 f4                mov    %eax,-0xc(%ebp)
return 0;
 80483be:       b8 00 00 00 00          mov    $0x0,%eax
}  
 80483c3:       c9                      leave  
 80483c4:       c3                      ret    
 80483c5:       90                      nop


 

编译

#gcc -g a2.c
反汇编

#objdump -dS a.out

#include <stdio.h>  

int main(void)  
{  
 8048394:       55                      push   %ebp
 8048395:       89 e5                   mov    %esp,%ebp
 8048397:       83 ec 10                sub    $0x10,%esp
int a=1;
 804839a:       c7 45 f4 01 00 00 00    movl   $0x1,-0xc(%ebp)
int b=2;
 80483a1:       c7 45 f8 02 00 00 00    movl   $0x2,-0x8(%ebp)
int c=0;
 80483a8:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%ebp)
if(b>c)
 80483af:       8b 45 f8                mov    -0x8(%ebp),%eax
 80483b2:       3b 45 fc                cmp    -0x4(%ebp),%eax
 80483b5:       7e 09                   jle    80483c0 <main+0x2c>
{
a=1;
 80483b7:       c7 45 f4 01 00 00 00    movl   $0x1,-0xc(%ebp)
 80483be:       eb 07                   jmp    80483c7 <main+0x33>
}
else
{
a=0;
 80483c0:       c7 45 f4 00 00 00 00    movl   $0x0,-0xc(%ebp)
}
return 0;
 80483c7:       b8 00 00 00 00          mov    $0x0,%eax
}  
 80483cc:       c9                      leave  
 80483cd:       c3                      ret    
 80483ce:       90                      nop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值