LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   segmentation fault in assembly code (https://www.linuxquestions.org/questions/programming-9/segmentation-fault-in-assembly-code-670886/)

tanoatlq 09-18-2008 03:32 PM

segmentation fault in assembly code
 
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?

tanoatlq 09-19-2008 09:26 AM

Wrong defines. They should be in reverse order. :-)


All times are GMT -5. The time now is 06:46 PM.