Author Topic: segmentation fault: why?  (Read 15900 times)

nobody

  • Guest
segmentation fault: why?
« on: September 18, 2008, 01:48:17 PM »
Hello,
I start to use nasm for a little bit of code with SDL libraries,
but now that I start to test a little bit of code, I get
a segmentation fault. This piece of code should only call
SDL_MapRGB(). The video was initialized in c main program.





; background is wheat

%define BACKGROUND_RED      0xf5
%define BACKGROUND_GREEN   0xde
%define BACKGROUND_BLUE      0xb3

; void demo (SDL_Surface *screen, SDL_PixelFormat *format, Uint8 bpp, int width, int height, Uint16 pitch, void *pixels);

%define pixels   (ebp + 8)
%define pitch   (ebp + 12)
%define height   (ebp + 16)
%define width   (ebp + 20)
%define bpp      (ebp + 24)
%define format   (ebp + 28)
%define screen   (ebp + 32)

segment .text
   global demo
   extern SDL_MapRGB

; local variables

%define background   (ebp - 4)

demo:   enter 4,0

;   Uint32 SDL_MapRGB (SDL_PixelFormat *, Uint8 r, Uint8 g, Uint8 b);

push dword BACKGROUND_BLUE
   push dword BACKGROUND_GREEN
   push dword BACKGROUND_RED
   push dword [format]
   call SDL_MapRGB
   add esp, 16
   mov [background], eax

leave
   ret



Any suspect?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: segmentation fault: why?
« Reply #1 on: September 18, 2008, 02:21:54 PM »
I don't think you should have to do this, but, in desperation, try:

lea eax, [format]
push eax

I *really* don't think you should have to do that... but I don't see too many other places it could be going wrong...

Best,
Frank

nobody

  • Guest
Re: segmentation fault: why?
« Reply #2 on: September 18, 2008, 05:19:47 PM »
No, that's not. Looking at include file of SDL seems that
it follow the standard C calling convection, so?
Two lines of code and I am becoming mad.. :-)

nobody

  • Guest
Re: segmentation fault: why?
« Reply #3 on: September 18, 2008, 07:54:41 PM »
Trying to write a little .c program that does like the
assembly code should do, and see the assembly output with
the -S option,  it seems that gcc add a lot of stuff,
working with more local variables that I do not use.
?!?!