Assembly-Level Representation of Programs on IA32 and x86-64

Below is the C code for example.

long example(long* p, long i)
{
       long t = *p + i;
       *p = t;
       return t;
}

 

       Equivalent assembly code that is compatible with IA32 machine is presented below.

example:
    pushl   %ebp
    movl    %esp, %ebp
    movl    8(%ebp), %edx
    movl    12(%ebp), %eax
    addl    (%edx), %eax
    movl    %eax, (%edx)
    popl    %ebp
    ret

     While the x86-64 version is following.

example:
    movq    %rsi, %rax
    addq    (%rdi), %rax
    movq    %rax, (%rdi)
    ret
     We can see there are some differences between the two fragments of code, including:
  • Instead of movl and addl instructions, we see movq and addq. The pointers and variables declared as long integers are now 64 bits rather than 32 bits.
  • We see the 64-bit versions of registers. The procedure returns a value by storing it in register %rax.
  • No stack frame gets generated in the x86-64 version. This eliminates the instructions that set up and remove the stack frame in IA32 code.
  • Arguments p and i are passed in registers rather than on the stack. This eliminates the need to fetch the arguments from memory.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值