gpt4 book ai didi

c++ - 从头开始在汇编中编写 for 循环

转载 作者:行者123 更新时间:2023-11-28 08:06:32 24 4
gpt4 key购买 nike

你好,我目前正在尝试自己学习 C++ 中的汇编。我的项目中有汇编代码,目前处于高级 c++ for 循环中,如果可能的话,我需要帮助将其转换为完全汇编代码,这是我目前的代码:

char temp_char;
for (int i = 0; i < length; i++){
temp_char = characters [i];
__asm {
push eax
push ecx
movsx ecx,temp_char
movsx eax,key
push ecx
push eax
call test
add esp, 8
mov temp_char,al
pop ecx
pop eax
}
}

最佳答案

您的 for 行包含三个部分。在组装级别思考时,有助于将它们分开。一个简单的方法是将 for 重写为 while:

char temp_char;

int i = 0;
while (i < length) {
temp_char = characters [i];
__asm {
push eax
push ecx
movsx ecx,temp_char
movsx eax,key
push ecx
push eax
call test
add esp, 8
mov temp_char,al
pop ecx
pop eax
}
i++;
}

您应该能够很容易地将 int i=0i++ 行转换为汇编代码。唯一剩下的就是 whilewhile 的顶部通常实现为条件和跳转(或条件跳转,如果您的平台支持此类操作)。如果条件为真,进入循环;如果条件为假,则跳过循环(跳转到末尾)。 while 的底部只是无条件跳回到循环顶部。

关于c++ - 从头开始在汇编中编写 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10182997/

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