大会code继续显示故障段 [英] Assembly Code keep showing segment fault
问题描述
为什么本次大会code组装和运行时的链接罚款,但显示段故障。该指令后评论给一个知道我想做的事。
Why this assembly code assemble and link fine but show segment fault in runtime. Commented after the instruction to give a idea what I wanted to do.
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位兼容。
I am using NASM
to assemble and ld
to link. This program will run on a 64-bit machine but I want it to be 32-bit compatible.
推荐答案
您想拥有的字符串在 ECX
的地址。那么,为什么你流行ESI
?使用 POP ECX
,你已经拥有它在正确的寄存器。你不需要它无论如何用于其他目的。
You want to have the address of the string in ecx
. So why do you pop esi
? Use pop ecx
and you already have it in the correct register. You don't need it anyway for some other purpose.
除此之外,你写入code段,这是不是在默认情况下写的。
Apart from that, you are writing to the code segment, which is not writable by default.
这篇关于大会code继续显示故障段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!