从头开始在程序集中编写for循环 你好,我目前正在尝试自己学习C++中的汇编。我在我的项目中有一个汇编代码,它目前在一个高级的C++循环中,如果需要的话,我需要帮助把它转换成完整的汇编,这里是我现在的代码:< /P> 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 } } chartemp\u char; for(int i=0;i

从头开始在程序集中编写for循环 你好,我目前正在尝试自己学习C++中的汇编。我在我的项目中有一个汇编代码,它目前在一个高级的C++循环中,如果需要的话,我需要帮助把它转换成完整的汇编,这里是我现在的代码:< /P> 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 } } chartemp\u char; for(int i=0;i,c++,visual-studio,visual-c++,assembly,for-loop,C++,Visual Studio,Visual C++,Assembly,For Loop,您的for行包含三个部分。当在组装级别进行思考时,它有助于将这些分离。一种简单的方法是将的重新编写为,而: char temp_char; int i = 0; while (i < length) { temp_char = characters [i]; __asm { push eax push ecx movsx ecx,temp_char m

您的
for
行包含三个部分。当在组装级别进行思考时,它有助于将这些分离。一种简单的方法是将的
重新编写为
,而

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++;
}
chartemp\u char;
int i=0;
while(i

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

只是语义:请注意,您正在寻找代码,而不是。汇编程序是将汇编转换成二进制代码的东西…@amit谢谢你编辑:)你为什么不简单地检查编译器的结果?我猜VisualC++也支持从编译C/C++代码的结果中输出汇编语言文件。或者,如果这样做失败,请在生成的二进制文件上使用反汇编程序来学习您的编译器。很抱歉,我试图查看反汇编程序,但对我来说没有太大意义。@Paul-如果您正在检查编译器的汇编输出,我建议在生成之前禁用所有形式的优化。这将使程序集尽可能真实地反映底层代码。经过大量优化的程序集最终可能会变得非常混乱。谢谢你的帮助,我现在有点接近了,仍然有点困惑,但我已经达到了目的,这是学习的本质:)@Paul-尽量从基础开始。创建您可以创建的最简单的循环,可能类似于(inti=0;i)的
for