Inline ASM with SDL Graphics (Not same as C/C++ coding result) ... :(

This is a discussion on Inline ASM with SDL Graphics (Not same as C/C++ coding result) ... :( within the Game Programming forums, part of the General Programming Boards category; Hello, thanks for reading my post. I hope you will be able to offer me some help for my problem. ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Inline ASM with SDL Graphics (Not same as C/C++ coding result) ... :(

    Hello, thanks for reading my post. I hope you will be able to offer me some help for my problem. I am programming a 2D engine using SDL, and I am having a small amount of trouble getting ASM to work correctly. Here's the code:

    Code:
    __asm 
    {
        // ... A bit of code here
        push 0xffffff         // In SDL this is 'white'
        mov  edx, DWORD PTR dest1    // 'SDL_Rect dest1;'
        push edx
        mov  ecx, DWORD PTR screen   // 'SDL_Surface *screen;'
        push ecx
        call    SDL_FillRect            // Calls 'SDL_FillRect(...)' function
        add   esp, 12
    
        // ... More code here
    }
    That code will fill the ENTIRE screen white, while:

    Code:
    SDL_FillRect(screen, &dest1, 0xffffff);
    Will give me what I need. Can you tell me what I am doing wrong?

    Thanks in Advance,
    Matt U.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Make sure you are pushing the arguments onto the stack in the correct order. Most Windows functions calls, if not all, use the PASCAL calling method where items are pushed left to right, where C pushes right to left. It's either that or vice versa - check your compiler help file.

    If you push in the wrong order, you will undoubtedly crash the entire system.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post I already did ...

    I have already done that. VC++ pushes from right to left. I can't figure out why the two same functions (but ASM and C/C++) give different results. I have never had this problem before.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking Sorry, it's my fault! :)

    I figured it out. I read the Listing Files incorrectly. Instead of:

    mov edx, DWORD PTR dest1

    It's supposed to be:

    lea edx, DWORD PTR dest1

    No help needed right now.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Ok.

    Big difference between loading register and loading effective address.

  6. #6
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    What part of tenn are you from?

  7. #7
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Cool Answering frenchfry :-P

    I am from middle Tenn. ... Around Nashville and Rutherford County
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 12:29 PM
  2. gcc inline asm: illegal instruction (core dump)
    By Sargnagel in forum C Programming
    Replies: 4
    Last Post: 10-28-2003, 01:41 PM
  3. Implementing SDL -Graphics
    By mr_william_lo in forum C++ Programming
    Replies: 0
    Last Post: 04-20-2003, 03:04 PM
  4. Graphics with SDL
    By Liger86 in forum Game Programming
    Replies: 1
    Last Post: 01-25-2003, 11:45 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21