如何打印汇编NASM是多少? [英] How to print a number in assembly NASM?
本文介绍了如何打印汇编NASM是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个寄存器整数,我怎么能打印呢?您可以显示一个简单的例子code?
Suppose that I have an integer number in a register, how can I print it? Can you show a simple example code?
我已经知道如何打印一个字符串,如你好,世界。
I already know how to print a string such as "hello, world".
我开发在Linux上。
I'm developing on Linux.
推荐答案
如果你已经在Linux上,没有必要自己做转换。只需使用的printf 来代替:
If you're already on Linux, there's no need to do the conversion yourself. Just use printf instead:
;
; assemble and link with:
; nasm -f elf printf-test.asm && gcc -m32 -o printf-test printf-test.o
;
section .text
global main
extern printf
main:
mov eax, 0xDEADBEEF
push eax
push message
call printf
add esp, 8
ret
message db "Register = %08X", 10, 0
注意的printf
使用 cdecl调用约定所以我们需要使用完毕后恢复堆栈指针,即每传递给函数的参数添加4个字节。
Note that printf
uses the cdecl calling convention so we need to restore the stack pointer afterwards, i.e. add 4 bytes per parameter passed to the function.
这篇关于如何打印汇编NASM是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文