为什么我从32位NASM汇编代码中得到此结果?

时间:2018-09-23 20:22:45

标签: linux assembly printf nasm

我的NASM汇编代码(在Linux中)如下:

   %macro write_string 2
    push %1
    call printf
    pop eax
    add esp, %2
    %endmacro
section .text
   global main            ;must be declared for using gcc
   extern printf
main:
   push ebp
   mov ebp, esp
   write_string msg1, len1
   write_string msg2, len2
   write_string msg3, len3
   mov esp, ebp
   pop ebp

 mov eax,1                ;system call number (sys_exit)
  int 0x80                 ;call kernel

section .data
msg1  db 'Hello, programmers!',0xA,0xD
len1  equ $ - msg1
msg2  db 'Welcome to the world of,', 0xA,0xD
len2  equ $- msg2
msg3  db 'Linux assembly programming! '
len3  equ $- msg3

执行此操作后(在nasm -f elf -o writeStrings.o writeStrings.asm && gcc -o writeStrings writeStrings.o之后),我得到以下输出:

Hello, programmers! Welcome to the world of, Linux assembly
programming! Welcome to the world of,

谁能告诉我为什么“欢迎来到这个世界”被复制?

任何帮助将不胜感激!

更新: 在每个msg之后添加0x00之后,现在的输出为: 您好,程序员! 欢迎来到世界,

现在不输出第三张照片。

更新: 我能够使它工作。非常感谢您的帮助!

0 个答案:

没有答案
相关问题