linux - 如何在汇编 NASM 中打印数字?

标签 linux assembly x86 nasm

假设我在寄存器中有一个整数,我该如何打印它?你能展示一个简单的示例代码吗?

我已经知道如何打印诸如“hello, world”之类的字符串。

我在 Linux 上开发。

最佳答案

如果您已经在使用 Linux,则无需自己进行转换。只需使用 printf相反:

;
; 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 calling convention所以我们之后需要恢复堆栈指针,即为每个传递给函数的参数添加 4 个字节。

关于linux - 如何在汇编 NASM 中打印数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8194141/

相关文章:

linux - Gedit 语法突出显示不起作用

c++ - 识别asm中的地址计算insns

c - "+&r"与 "+r"有何不同?

c++ - boost::bind 返回一个函数对象,它是需要指针的函数的参数

Android中间件c程序: Unable to create directory,只读文件系统

linux - float 显示十六进制 x86-64 nasm linux

assembly - 基本 FPU 指令/堆栈概述?

c - 上证有效值计算

x86 - 中断向量表位于何处?

c - C 中的分段 11 试图重新创建 Stty