我正在用 nasm 编码,但我不明白发生了什么。 linux 发行版是 ubuntu 16 64 位,但 NASM 运行在 32 位
预期输出 -->“数字是:2”
实际输出-->“数字是:134520868”
代码:
%include "io.inc"
section .data
n1 db 2 ; i know its a bad practice to define a db variable, its just for a test
msg: db 'number is: %d',10,0
section .text
extern printf
global main
main:
push ebp
mov ebp, esp
push dword n1
push msg
call printf
mov esp, ebp
pop ebp
ret
我尝试用 dd 定义 n1,或者推送 n1 的内容,即使使用像 eax 这样的寄存器。
不知道我在做什么
您想要一个 32 位数字,因此使用
dd
并且您不想打印变量的地址,而是打印其内容。所以:
n1 dd 2 ; ...
和
push dword [n1]
push msg
call printf