Hi. I am trying to use assembly in C++, and need a few pointers(pun intended) lol
I want to use C++ structs as operands, but can't figure out how.
my code is like this so far:
TEST.CPP
extern "C" WORD _add(WORD num1, WORD num2);
int _tmain(int argc, _TCHAR* argv[])
{
WORD number = 5;
WORD number2 = 5;
number = _add(number, number2);
cout << number << endl;
getch();
return 1;
}
_ADD.ASM
.586
.MODEL FLAT, C
.STACK
.DATA
.CODE
_add PROC num1:WORD, num2:WORD
mov ax, num1
mov bx, num2
add ax, bx
ret
_add ENDP
END
I cant figure out how to use pointers to memory as operands =(
this is what I was trying, could someone point out what I am doing wrong please?
TEST.CPP
extern "C" WORD _add(WORD *num1, WORD *num2);
int _tmain(int argc, _TCHAR* argv[])
{
WORD *number;
WORD *number2;
*number = 5;
*number2 = 5;
number = _add(number, number2); //pass the address in
cout << number << endl;
getch();
return 1;
}
_ADD.ASM
.586
.MODEL FLAT, C
.STACK
.DATA
.CODE
_add PROC num1:DWORD, num2:DWORD ;pointers are 4 bytes or ulong
mov ax, [num1] ;dereference to get the data pointed to by num1
mov bx, [num2] ;and num2
add ax, bx
ret
_add ENDP
END
I know I have a lot of errors..but I cant find a decent clearly written article on this for some reason..
Thanks again =)