c++ 中的内联 asm 与 __asm 的对比
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 //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,名称给了我这个编译错误:C2443:操作数大小冲突
更新 2:莉亚工作正常。
您似乎正在寻找lea
指令,它将某些交易品种的有效地址加载到寄存器中。以下指令将以esi
存储name
的地址。
lea esi, name
name
已经(或者更确切地说是衰减到)一个指针。只需使用mov esi, name
.
move esi, name
已经是名称的地址。如果你想要内容(名称[0]),你会使用
move esi, [name]
lea
是你要找的:
#include <stdio.h>
int main()
{
char name[25];
char* fmt = "%pn";
__asm {
lea eax,name
push eax
mov eax,fmt
push fmt
call printf
}
return 0;
}
相关文章:
- 使用C++获取程序的 ASM
- 在 c++ 中使用 x86 DIV 的这个 asm 块有什么用?
- g++ -O3 为 loop 创建了奇怪的指令 - 两个具有相同 asm 的版本
- Extern "C"错误在'int'之前'asm'或'__attribute__'
- 了解 C/C++ 中 Windows / MSVC 的一些反调试内联 asm
- 尝试使用 x86 asm SSSE3 将大端转换为小端序
- 如何使用"asm volatile"编写 btr 指令
- objdump 不显示机器代码,但显示 ASM
- 未使用的 asm() 在不受支持的体系结构上的行为
- 内联asm编译器屏障(内存阻塞器)是算作外部函数,还是算作静态函数调用
- std::mutex::lock() 产生奇怪(和不必要的)ASM 代码
- 为什么发出空asm命令会交换变量
- C++-更改另一个文件的ASM指令
- 尝试用纯 c 编程 arduino,得到以下错误:预期的"="、""、";",'asm'或"打印"之前的'__attribute__'|
- C++/ASM:按值传递使用 xmm0,但按引用使用 rdi
- 有人知道可以使用 c++ 以字节为单位编码 asm 字符串的任何东西吗?
- 优化了 VC++ 和 ASM 中的代码
- 如何在 Linux asm 中正确返回双精度值
- 使用读取[EBP 4]的MSVC内联ASM移植到64位
- 从 ASM 调用C++代码中标准库的链接