汇编代码一直显示段故障

时间:2013-11-03 04:25:29

标签: linux assembly x86 system-calls

为什么这个汇编代码汇编和链接正常但在运行时显示段错误。在说明之后评论我想要做什么。

  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位兼容。

1 个答案:

答案 0 :(得分:1)

您希望在ecx中包含字符串的地址。那你为什么要pop esi?使用pop ecx,您已将其放入正确的注册表中。无论如何你还不需要它用于其他目的。

除此之外,您正在写入代码段,默认情况下不可写。