【发布时间】:2013-11-03 04:25:29
【问题描述】:
为什么这个汇编代码可以正常组装和链接,但在运行时显示段错误。在说明后发表评论,说明我想做什么。
jmp short init
action:
pop esi
xor eax, eax
mov byte [esi+24], al ;null terminating the string.
mov dword [esi+25],24 ;length of the string
mov al,4 ;syscall write
mov ebx,1 ;standard out
lea ecx,[esi] ;<<---------- Unsure about this. probably load the address of the string to ecx
mov edx,[esi+25] ;<<-- load edx with string length
int 80h
init:
call action
db "what a pity! not working#LLLL"
我正在使用NASM 组装和ld 链接。该程序将在 64 位机器上运行,但我希望它兼容 32 位。
【问题讨论】:
-
你的字符串似乎在
section .text(如果你不说,Nasm 将默认为)这是只读内存。试图改变它会出现段错误。如果它运行,它将永远循环。我在那里没有看到sys_exit... -
原来的程序有一个 sys_exit。如何让它可写?
-
在我看来是递归的 - 进入 :init 并再次调用操作...
标签: linux assembly x86 system-calls