MSVC inline assembly and structs problem

Started by
0 comments, last by Axenation 20 years, 1 month ago
im fairly new to assembly and im having trouble accessing some data from an SDL_Surface struct (it''s definition is below my function). i''ve tried doing a couple of different things like MOV EDX, surface IMUL someReg, [EDX+16] // surface->pitch ??? this is the code im writing :

static void putpixel24(SDL_Surface *surface, int x, int y, uint32 color)
{
    //

    //  How do i access surface->pitch in assembly?

    //

    uint32 pitch = surface->pitch;

    //  EDX = SDL_Surface *surface

    __asm mov   edx, surface

    //  move address of surface->pixels into EBX

    __asm mov   ebx, [edx+20]

    //  EAX = y * surface->pitch

    __asm mov   eax, y
    __asm imul  eax, pitch         //<---------- ?

    __asm add   ebx, eax

    //  x * 3 (using adds instead of imuls)

    __asm add   ebx, x 
    __asm add   ebx, x
    __asm add   ebx, x

    //  [ebx] is now the address of the pixel we wish to change

    
    __asm mov   eax, color
    __asm mov   [ebx], al
    __asm shr   eax, 8
    __asm mov   [ebx+1], ax
}
this is the definition of an SDL_Surface:

typedef struct SDL_Surface {
	Uint32 flags;				/* Read-only */
	SDL_PixelFormat *format;		/* Read-only */
	int w, h;				/* Read-only */
	Uint16 pitch;				/* Read-only */
	void *pixels;				/* Read-write */
	int offset;				/* Private */

	/* Hardware-specific surface info */
	struct private_hwdata *hwdata;

	/* clipping information */
	SDL_Rect clip_rect;			/* Read-only */
	Uint32 unused1;				/* for binary compatibility */

	/* Allow recursive locks */
	Uint32 locked;				/* Private */

	/* info for fast blit mapping to other surfaces */
	struct SDL_BlitMap *map;		/* Private */

	/* format version, bumped at every change to invalidate blit maps */
	unsigned int format_version;		/* Private */

	/* Reference count -- used when freeing surface */
	int refcount;				/* Read-mostly */
} SDL_Surface;
PS...i know this function would probably be faster written in C++, im just trying to learn new things.
Now I get a cookie!
Advertisement
figured it out...i needed to type "word ptr" like this.

mov esi, surfacexor edx, edxmov  dx, word ptr [esi+10h] //surface->pitch
Now I get a cookie!

This topic is closed to new replies.

Advertisement