从头开始在程序集中编写 for 循环
Writing a for loop in assembly from scratch
你好,我目前正在尝试自己学习 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=0
和i++
线转换为装配体。 唯一剩下的就是while
. while
顶部通常实现为条件和跳转(或条件跳转,如果您的平台支持此类操作)。 如果条件为 true,则进入循环;如果条件为 false,则跳过循环(跳到最后)。 while
的底部只是无条件地跳回到循环的顶部。
相关文章:
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么我的for循环不能正确获取argv
- 在基于范围的for循环中使用结构化绑定声明
- 通过for循环使用用户输入填充列表
- 使用for循环检查数组中的重复项
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 正在使用for循环创建QScatterSerie
- Python中的for循环与C++有何不同
- 在更改for循环的第三部分后,未使用for循环结果
- 在 for 循环中查找问题时遇到困难
- 嵌套for循环C++的问题(初学者)
- 如何用for循环在c++中生成单词三角形
- 如何在for循环中包含两个索引值的测试条件
- 带有多个独立参数的C++For循环
- 为什么我的程序在for循环中k=0时返回垃圾值
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- C++-For循环未执行
- 基于范围的 for 循环:迭代使用一个元素扩展的向量
- C++ 无法在字符数组中使用 for 循环打印字母模式