How to access C structs from _asm scope ?

Started by Max_Power_Up, August 22, 2007, 02:12:00 PM

Previous topic - Next topic

Max_Power_Up


Good afternoon everybody.

I have the worst of problems, I have a set_pixel function which
takes the address to a structure
that I have defined in C code,
the problem is that I want to set the values in
that structure using an assembly block
so that I can circumvent alot of instructions.

Well, its not working, I keep either getting an
error or an exception is generated (access violation)
or it simply just doesn't work.

This is what I have :


typedef struct tagRGBT
{
unsigned char R;
unsigned char G;
unsigned char B;
}RGBT;

void set_pixel(RGBT *screen,int x,int y,unsigned char r,unsigned char g, unsigned char b)
{
int index = (y * W)+x;
__asm{
       mov ax, r;
mov bx, [screen];
add bx, index;
mov bx, ax;

mov ax, g;
inc bx;
mov bx, ax;

mov ax, b;
inc bx;
mov bx, ax;
         }
}


Any help would be appreciated - thanks...
[/color]

frankie

Have you considered that you're using a 32 bits OS compiler?
Your code is DOS 16 bit, it will never work because actual pointers are 32 bits wide.
Last you have the alignement problem  from your previous post.
Before to add assembler code I would suggest to code a working routine in C, than you can instruct the  compiler to produce assembler output using the switch /Tx86-asm. So you can look at it ad use as base for faster assembler code.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide