汇编" mov"指令

时间:2014-07-14 21:16:26

标签: assembly instruction-set mov

我通过将c程序与其程序集等效进行比较来学习汇编。

这是代码。

.file   "ex3.c"
.section    .rodata
.LC0:
    .string "I am %d years old.\n"
.LC1:
    .string "I am %d inches tall.\n"
    .text
    .globl  main
    .type   main, @function
main:
    pushl   %ebp    //establish stack frame//
    movl    %esp, %ebp //move esp into ebp, all contents saved down stack//
    andl    $-16, %esp //16 from esp for local var space//
    subl    $32, %esp//stack frame reserving - 32 bytes//
    movl    $10, 24(%esp)
    movl    $72, 28(%esp)
    movl    24(%esp), %eax
    movl    %eax, 4(%esp)
    movl    $.LC0, (%esp)
    call    printf
    movl    28(%esp), %eax
    movl    %eax, 4(%esp)
    movl    $.LC1, (%esp)
    call    printf
    movl    $0, %eax
    leave
    ret
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2"
    .section    .note.GNU-stack,"",@progbits

对于这一行:

movl    $10, 24(%esp)

如果我理解正确,那就是将10的值移到esp寄存器中。但是24做了什么?我不认为它被转移到esp中,因为要移动的值由" $"表示。 (我认为)

2 个答案:

答案 0 :(得分:10)

movl $10,24(%esp)

表示:将文字十进制10长(4字节)移动到一个4字节的内存位置,该位置从(esp寄存器加十进制24)指向的地址开始 - 基本上它是一个局部变量。

答案 1 :(得分:8)

换句话说movl $10,24(%esp)

表示:将10加载到*(esp + 24)

在C中等于:

*(unsigned long *)(myptr + 24) = 10;

其中myptr的值为esp寄存器。

相关问题