【发布时间】:2021-07-09 01:10:53
【问题描述】:
我是汇编新手,据我所知,.code 与 .text 相同,但使用 .code 时下面的代码会崩溃。
segment .data
msg db "hello, world", 0xa
len equ $ - msg
section .text
global _start
_start:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80
mov ebx, 0
mov eax, 1
int 0x80
nasm -f elf64 -o hello.o hello.s
ld -s -o hello hello.o
hello, world
sed -i s/.text/.code/ ./hello.s
nasm -f elf64 -o hello.o hello.s
ld -s -o hello hello.o
./stack.sh: line 8: 4621 Segmentation fault (core dumped) ./hello
实际上,我不认为这有什么不同。为什么会这样?
【问题讨论】:
-
你学错了。在 nasm 中,
.code无法识别。请参阅manual。特别注意无法识别的部分是noexec。 -
section .text是 Windows MASM.code的 NASM / Linux 等效,即您放置指令的位置。section .code实际上并没有在 NASM 中做你想做的事情。