NASM Forum > Programming with NASM

segmentation fault when using ebp-4/ebp-8

(1/1)

iAnzu:
Hello and thanks for reading!

Windows 64 / Nasm x86 / gcc

A friend helped me with some code and he used ebp-4/ebp-8 to store temporal variables, I thought it would make it more readable to allocate variables in .bss section and use them. Later, I thought I didn't want to have too many variables in .bss section and decided to go back to my friends implementation, also, at that time, my brain already started to like to use ebp-X to store temporal variables.

Linux 64 / Nasm x86 / gcc

Segmentation fault, and I didn't know why for a really long period of time. it occurred to me, as a last resort, to create variables for ebp-4 and others. That made it, no more segmentation fault; but I'm still curious about why did this happened? Why couldn't I use ebp-4 to store temporal variables on Linux when on Windows it was just fine?

nasm -f elf32 -o
gcc  -m32 -o

%macro HexToBin 3 
        ...;code
        ...
        mov         dword [ebp-4], dword 0  ; Segmentation fault
        ...
        ...;code
%%hextobinE:
%endmacro

fredericopissarra:
Are you allocating space on stack for local vars?


--- Code: ---  push ebp
  mov  ebp,esp
  ...
  sub  esp,4   ; allocate 4 bytes of "local" stack space.
  ...
  mov dword [ebp-4],0
  ...
  add  esp,4  ; deallocate
  ...
  pop ebp
  ret
--- End code ---

iAnzu:
Thanks a lot, that solved it! I'm still curious, why windows didn't catch/notice this problem?

Navigation

[0] Message Index

Go to full version