LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-18-2008, 03:32 PM   #1
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Rep: Reputation: 30
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?
 
Old 09-19-2008, 09:26 AM   #2
tanoatlq
Member
 
Registered: Mar 2007
Posts: 157

Original Poster
Rep: Reputation: 30
Wrong defines. They should be in reverse order. :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with my code? C++ and segmentation fault mesh2005 Programming 12 07-25-2007 02:42 PM
simple c code but whenever running getting segmentation fault with getch() invincible.rish Linux - General 1 01-26-2007 06:55 AM
when code tries to execute at that time i am getting segmentation fault dayalan_cse Programming 1 12-17-2006 10:30 AM
x86 Assembly - segmentation fault? jrtayloriv Programming 1 07-05-2004 12:52 AM
segmentation fault in following peice of code :please help linorg Programming 2 03-18-2004 08:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration