【发布时间】:2020-06-06 22:32:32
【问题描述】:
我正在尝试通过内联程序集打印数组。 Printf 函数将堆栈上的值解释为它需要打印的地址并导致错误(屏幕截图:https://prnt.sc/r692d3)。如果我将地址传递给 printf,它会打印出像这样的垃圾值:(屏幕截图:https://prnt.sc/r691de)。
另外,如果有人知道 - 如何将 '\n' 放在带有内联 ASM 的字符串中?谢谢:)
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;
}
}
【问题讨论】:
标签: c++ inline-assembly