extern printf ; the C function, to be called
SECTION .data ; Data section, initialized variables
a: dd 5 ; int a=5;
fmt: db "a=%d, eax=%d",10,0 ; The printf format, "\n",'0'
SECTION .text ; Code section.
global main ; the standard gcc entry point
main: ; the program label for the entry point
push ebp ; calling convention
mov ebp, esp
mov eax, [a] ; put a from store into register
add eax, 2 ; a+2
push eax ; value of a+2
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; Call C function
add esp, 12 ; pop stack 3 push times 4 bytes
mov esp, ebp ; returning convention
pop ebp ; same as "leave" op
mov eax,0 ; normal (no error) return value
ret ; return
我感到有点困惑。我知道dd
声明了一个4字节的值并在其中存储了5个字节。在汇编中存储eax中的值
1)然后mov eax, [a]
将它存储在eax寄存器中。但不是AX只有2个字节的寄存器。它如何存储一个4字节的值?
2)fmt: db "a=%d, eax=%d",10,0
我知道fmt是一个位置名称,db声明了一个字节,但接下来的代码是做什么的?
E代表扩展。 EAX存储32位。 – Dzenly
关于#2,我建议您查看有关printf函数如何与格式字符串一起工作的信息。 –