gpt4 book ai didi

c - 如何在内联汇编中声明字符缓冲区?

转载 作者:行者123 更新时间:2023-11-30 19:50:38 25 4
gpt4 key购买 nike

到目前为止我有以下代码:

char* s;
s = new char[10];

__asm
{
mov ebx, s
mov byte ptr[ebx], 0x48 ;'H'
mov byte ptr[ebx + 1], 0x65 ;'e'
mov byte ptr[ebx + 2], 0x6C ;'l'
mov byte ptr[ebx + 3], 0x6C ;'l'
mov byte ptr[ebx + 4], 0x6F ;'o'
mov byte ptr[ebx + 5], 0x0A ; 'new line'
mov byte ptr[ebx + 6], 0;
mov eax, ebx
push eax
call DWORD ptr printf
pop ebx
}

我想在 asm 中声明一个 char 数组而不使用 DB,那会是什么样子?

最佳答案

也可以这样:

call do_print
db "Hola...Hello", 0Ah,0
do_print:
call DWORD ptr printf
pop rcx

在调用 do_print 时,我们将缓冲区“Hello..”的实际起始地址放入堆栈返回地址,汇编语言很简单,改为 pop rcx 而不是 pop [esp]

关于c - 如何在内联汇编中声明字符缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58980426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com