Author Topic: seg fault when assing value to memory  (Read 8583 times)

nobody

  • Guest
seg fault when assing value to memory
« on: August 18, 2007, 05:25:46 PM »
hallo,

i have a short program:

section .data
   var dw 0

section .text
   global _start

_start:
   mov eax,dword 0x01
   mov dword [var],eax ; causes segmentaion fault
   mov ebx,0
   mov eax,1
   int 0x80

can someone tell me, what is goes wrong?

thanks
nico

nobody

  • Guest
Re: seg fault when assing value to memory
« Reply #1 on: August 18, 2007, 08:08:01 PM »
I can't reproduce this problem.

There's an error in your code. "var" is declared as "word" - 16 bits. (I used to get confused about this - "dw" sounds like "dword", but it's "data word" - you want "dd" - "data dword"...) Then you move eax into it. This *could* cause a segfault, if your variable was the very last thing in valid memory - but it isn't.

I thought this might be something that 0.99.xx might screw up... but that isn't it - 0.99.02 gets it right.

Try "ndisasm -u -o 8048000h -s 8048080h myprog | less" and tell us what you see. Should be something like "mov [0x8049098], eax".

Outside of the "dw" vs "dd" problem, your code looks fine to me, and I can't get it to segfault. Not the first time I've been confused - not even the first time today...

Best,
Frank