c++ 中的内联汇编在 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 //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;
我不知道如何获取 asm 块中 chay 数组的地址。 当我尝试使用“&”时例如 &name 我在编译时遇到错误:
error C2400: inline assembler syntax error in 'second operand'; found 'AND'
更新:
mov esi,name给了我这个编译错误:C2443:操作数大小冲突
更新2: lea 工作正常。
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 //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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您似乎正在寻找 lea 指令,它将某个符号的有效地址加载到寄存器中。以下指令将
name
的地址存储在esi
中。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 ofname
inesi
.name
已经是(或者更确切地说衰减为)一个指针。只需使用mov esi, name
即可。name
is already (or rather decays to) a pointer. Just usemov esi, name
.已经是名字的地址了。如果您想要内容(名称[0]),您可以使用
already is the address of name. If you wanted the content (name[0]) you would use
lea
是您正在寻找的:lea
is what you're looking for: