【发布时间】:2015-12-11 06:26:22
【问题描述】:
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。
1) 然后mov eax, [a] 将其存储在 eax 寄存器中。但是 AX 不只是一个 2 字节的寄存器。它如何存储一个 4 字节的值?
2) fmt: db "a=%d, eax=%d",10,0 我知道 fmt 是一个位置名称,而 db 声明了一个字节,但是剩下的代码是做什么的呢?
【问题讨论】:
-
E 代表扩展。 EAX 存储 32 位。
-
关于 #2,我建议您查找有关 printf 函数如何处理格式字符串的信息。
标签: assembly