我正在尝试运行以下代码,这些代码是我在https://www.tutorialspoint.com/assembly_programming/assembly_macros.htm上用汇编语言编写的宏的示例
; A macro with two parameters
; Implements the write system call
%macro write_string 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
write_string msg1, len1
write_string msg2, len2
write_string msg3, len3
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
我将此代码另存为example.asm,并尝试按以下方式编译和运行它:
nasm -f elf64 example.asm
ld -s -o example example.o
./example
但是,我遇到了细分错误。可能是什么原因?
更新:在gdb中运行后,我会得到:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004000c4 in ?? ()
当我做回溯时,我得到:
#0 0x00000000004000c4 in ?? ()
#1 0x0000000000000001 in ?? ()
#2 0x00007ffffffee1bf in ?? ()
#3 0x0000000000000000 in ?? ()