I am having a lot of trouble accessing a value in an array of chars at a specific location. I am using inline-assembly in C++ and using visual studio (if that is of any help). Here is my code:
char* addTwoStringNumbers(char *num1)
{
// here is what I have tried so far:
movzx eax, num1[3];
mov al, [eax]
}
When I debug, I can see that num1[3] is the value I want but I can’t seem to make either al or eax equal that value, it seems to always be some pointer reference. I have also played around with Byte PTR with no luck.
I’m not good neither at inline assembly, neither at MASM syntax, but here are some hints:
1) Try this:
(movzx is for unsigned char, so we used movsx)
2) You need to pass the value from
eaxto C. The simpliest way is to declare a variable and to put results there:int rez; __asm { mov rez, eax; };3) If you want to write the whole function in assembly, you should consider using the
nakedkeyword (and read about calling conventions). If not, make sure you preserve registers and don’t damage the stack.