PDA

Click to See Complete Forum and Search --> : Convert this to C/C++


Warmaster199
Mar 21st, 2001, 03:06 PM
Can someone please convert this to inline assembler(For use with BorlandC or C code? It's needed quite urgently.


public _setbxdx
.MODEL SMALL ;whatever
.CODE

set_struc struc
dw ? ;old bp
dd ? ;return addr (always far call)
p_bx dw ? ;reg bx value
p_dx dw ? ;reg dx value
set_struc ends

;HELP CONVERT THIS FUNCTION TO C/C++!!!
_setbxdx proc far ; must be FAR
push bp
mov bp,sp
mov bx,[bp]+p_bx
mov dx,[bp]+p_dx
pop bp
ret
_setbxdx endp
END


in C, the function prototype is "far setbxdx(int, int);"

I can get most of of the conversion, but I want it to work with the "REGS" structure. I've already posted this in the ASM forum, but it's in more depth here.

I need this urgently!

PsyVision
Mar 21st, 2001, 03:09 PM
www.softseek.com

Look in their programming section and it may have one.

Warmaster199
Mar 21st, 2001, 03:44 PM
Sorry, I didn't find anything there

Warmaster199
Mar 21st, 2001, 04:47 PM
This is important! I need help soon!

Mar 21st, 2001, 11:33 PM
I see you pushing bp.. what is in bp at the time of this?

also, can I see what you have converted so far.. maybe i can help...

Knight

Mar 22nd, 2001, 02:08 PM
Here, try this...

void setbxdx(int a_bx, int a_dx)
{
__asm
{
mov bx, a_bx
mov dx, a_dx
}
}

Knight Vision

Warmaster199
Mar 22nd, 2001, 04:06 PM
It has to have a return of the FAR type. That's why it pushes/pops bp to return it(I think). I got this code from some code from www.VESA.org It's from their VBE3.0 Specifications. This is to help in switching the videocard's memory banks by a method called Direct-Banking.

Cybrg641 has helped me and has converted it to this:

FAR setbxdx(int, int);
//-----------------------------------------------------------------
struct set_struc
{
WORD Oldbp; // old bp
DWORD rAddr; // return addr
WORD p_bx; // reg bx value
WORD p_dx; // reg dx value
};
//-----------------------------------------------------------------
FAR setbxdx(int p_bx, int p_dx)
{
asm {
push bp
mov bp, sp
mov bx, [bp] + p_bx
mov dx, [bp] + p_dx
pop bp
}
return 0;
}


It looks good to me... What do you guys say?