im trying to store the address of Label1: into my byte pointer.....it compiles but i am getting wierd outputs.....any help is greatly appreciated! -thx

int _tmain(int argc, _TCHAR* argv[])
{
char *address = 0;


__asm {
mov eax, Label1
mov address,eax
}




Label1:
cout << *address;

getchar();

return 0;
}
Posted on 2011-02-22 11:13:10 by dougfunny
change to this:

lea eax, Label1

This is equivalent to "eax = &Label1", which is what you really wanted to do.

Posted on 2011-02-23 02:00:39 by Homer
unfortunately i'm still getting invalid results, it's printing a wierd "i" character as the address.
Posted on 2011-02-24 22:44:38 by dougfunny
The address will be a 32-bit value. The memory variable where you are storing the retrieved address is declared as a "char", i.e. an 8-bit value.

Because more than one byte will be reserved for your data section, the retrieved address may effectively be stored in its entirely. HOWEVER, your "cout << *address" instruction will then most probably be interpreted as printing a single byte, which would be the low byte of the address.

Change the memory variable to a 32-bit value, i.e. int *address = 0, and it should work if the cout function converts the binary value to ascii before printing it. Otherwise, you will need to call another function to convert it into a declared text buffer and then print the content of that buffer.
Posted on 2011-02-24 22:59:28 by Raymond
why does mov and lea both give me the address????? also char* is a 32bit value since it's a pointer....i should be able to use it to store a 32bit address

int main(int argc, char *argv[])
{
int *address = 0;
int *address2 = 0;


__asm {
lea eax, Label1 // mov worked as well
mov address,eax
mov eax, Label2 // mov worked as well
mov address2,eax
}



Label1:
Label2:
std::cout << std::hex << address << std::endl;
std::cout << std::hex << address2;

getchar();

return 0;

}

Posted on 2011-03-04 18:08:11 by dougfunny

why does mov and lea both give me the address?????


There's more than one way that leads to Rome.
In this particular case, mov and lea do the same. But lea can do things that mov can't, and vice versa.
Posted on 2011-03-05 03:04:35 by Scali
You need to use LEA if you want to reference a local variable, since those are calculated relatively to ESP or EBP... LEA can encode that, whereas MOV only handles raw integers. A label is static address, and can thus be encoded as raw integer.

Be very careful what you do with references to labels in inline assembly. Heck, in general, you should mostly avoid inline assembly, pretty much anything worth dropping down to assembly level to do is worth doing as a proper external assembly module.
Posted on 2011-03-08 04:33:06 by f0dder