Inline asm in c++ in vs __asm
char name[25];
int generated_int;
for(int i = 0; i<sizeof(name); i++)
{
name[i] = (char)0;
}
cout << "Name: ";
cin >> name;
int nameLen = strlen(name);
__asm
{
pusha;
mov esi, &name开发者_StackOverflow社区 //I got error here, I cant use "&". How to move name address to esi?
mov ecx, nameLen
mov ebx, 45
start:
mov al, [esi]
and eax, 0xFF
mul ebx
inc esi
add edi, eax
inc ebx
dec ecx
jnz start
mov generated_serial, edi
popa
}
cout << endl << "Serial: " << generated_serial << endl << endl;
I don't know how to get address of my chay array in asm block. When I try to use "&" e.g. &name i get error while compiling:
error C2400: inline assembler syntax error in 'second operand'; found 'AND'
UPDATE:
mov esi, name gives me this compile error: C2443: operand size conflict
UPDATE 2: lea is working fine.
You seem to be looking for the lea
instruction, which loads the effective address of some symbol into a register. The following instruction will store the address of name
in esi
.
lea esi, name
name
is already (or rather decays to) a pointer. Just use mov esi, name
.
move esi, name
already is the address of name. If you wanted the content (name[0]) you would use
move esi, [name]
lea
is what you're looking for:
#include <stdio.h>
int main()
{
char name[25];
char* fmt = "%p\n";
__asm {
lea eax,name
push eax
mov eax,fmt
push fmt
call printf
}
return 0;
}
精彩评论