内联程序集printf将整数解释为地址
Inline assembly printf interpreting integers as an address
我正在尝试通过内联程序集打印数组。Printf函数一直将堆栈上的值解释为需要打印的地址,并导致错误(屏幕截图:https://prnt.sc/r692d3)。如果我将地址传递给printf,它就会打印出如下垃圾值:(屏幕截图:https://prnt.sc/r691de)。此外,如果有人知道如何使用内联ASM将'n'
放入字符串中?谢谢:(
int main()
{
int mas[5] = { 1,2,3,4,5 };
int32_t diff = sizeof(int);
__asm
{
mov esi, 0x0
lea ecx, [mas]
mov eax, [ecx]
push ecx
call printf; Here it tries to read value '1' as an address
pop eax
loop_t:
xor ebx, ebx; Clear the registers
xor ecx, ecx;
lea ecx, [mas]; ECX = &mas
mov ebx, diff;
add ebx, ecx; &mas + diff
mov eax, [ebx]; Transfer the value
push eax; Push it on stack
call printf; Same thing here, interprets it as an address
pop eax;
add diff, 0x4;
inc esi; Cleanup process and looping back on
cmp esi, 0x5;
jne loop_t;
}
}
printf
函数的第一个参数是格式字符串,即指向以null结尾的字符数组的第一个字符的指针。因此,第一个参数将始终被视为一个地址。
如果将值1作为第一个参数传递给printf(最后将其推到堆栈上(,则它将尝试从地址1读取格式字符串(这将失败(。
相关文章:
- 将数组的地址分配给变量并删除
- 空基优化子对象的地址
- 请解释"函数1(p1,p2,p3);"的输出
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 如何在c++程序中找到函数的地址
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 被解释为低级别const的const对象的地址
- 将地址分配给本地指针后,公共对象的变量将消失
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 内联程序集printf将整数解释为地址
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- ob->我应该返回 ob "this" 的地址,但它返回 i ,任何解释?
- 如何解释地址固定器输出
- Visual Studio,解释变量的地址
- 使LLDB将地址重新解释为指向模板实例化类型对象的指针
- 使用reintepret_cast解释对象地址
- 使用地址解释强制转换const
- PE文件中签名地址移位的解释