gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > problem with inline assemble in visualboyadvance source

#176124 - ww2000e - Thu Apr 14, 2011 8:02 am

in src/sdl/sdl.cpp
Code:

.........
#define SDL_CALL_STRETCHER \
  {\
    __asm mov eax, stretcher\
    __asm mov edi, dest\
    __asm mov esi, src\
    __asm call eax\
  }
..........


 switch(sizeOption) {
    case 0:
      for(i = 0; i < srcHeight; i++) {
        SDL_CALL_STRETCHER;
        src += srcPitch;
        dest += destPitch;
      }
      break;
     ......
 }

..........

what do these lines do in assembly?
__asm mov eax, stretcher\
__asm mov edi, dest\
__asm mov esi, src\
__asm call eax\[/code]

#176125 - Dwedit - Thu Apr 14, 2011 9:02 am

It means there's a function written in assembly called "stretcher", and it wants its arguments passed in through the EDI and ESI x86 registers.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#176126 - ww2000e - Thu Apr 14, 2011 9:43 am

Code:

.........
#define SDL_CALL_STRETCHER \
  {\
    __asm mov eax, stretcher\
    __asm mov edi, dest\
    __asm mov esi, src\
    __asm call eax\
  }
..........

u8 sdlStretcher[16384];

void systemDrawScreen()
{
    u32 *stretcher = (u32 *)sdlStretcher;
    ........
   
     switch(sizeOption) {
    case 0:
      for(i = 0; i < srcHeight; i++) {
        SDL_CALL_STRETCHER;
        src += srcPitch;
        dest += destPitch;
      }
      break;
     
     ......
 }
}
..........

but stretcher is a point to a array sdlStretcher.

and sdlStretcher's value just like:

Code:

#define SDL_LONG(val) \
  *((u32 *)&sdlStretcher[sdlStretcherPos]) = val;\
  sdlStretcherPos+=4;

#define SDL_AND_EAX(val) \
  sdlStretcher[sdlStretcherPos++] = 0x25;\
  SDL_LONG(val);

#define SDL_AND_EBX(val) \
  sdlStretcher[sdlStretcherPos++] = 0x81;\
  sdlStretcher[sdlStretcherPos++] = 0xe3;\
  SDL_LONG(val);
...........
...........

0x25,0x81,0xe3... is machine code ?

#176127 - kusma - Thu Apr 14, 2011 10:28 am

ww2000e wrote:

and sdlStretcher's value just like:

Code:

#define SDL_LONG(val) \
  *((u32 *)&sdlStretcher[sdlStretcherPos]) = val;\
  sdlStretcherPos+=4;

#define SDL_AND_EAX(val) \
  sdlStretcher[sdlStretcherPos++] = 0x25;\
  SDL_LONG(val);

#define SDL_AND_EBX(val) \
  sdlStretcher[sdlStretcherPos++] = 0x81;\
  sdlStretcher[sdlStretcherPos++] = 0xe3;\
  SDL_LONG(val);
...........
...........

0x25,0x81,0xe3... is machine code ?


Yes, looks like run-time code-generation.