【发布时间】:2015-04-29 11:46:49
【问题描述】:
目前我正在学习 x86 汇编作为我的 uni 模块之一,我有一个用 c++ 编写的程序,它接受一个 6 个字符的字符串并根据加密密钥对其进行加密。
encrypt_chars 的代码:
void encrypt_chars(int length, char EKey)
{
char temp_char; // char temporary store
for (int i = 0; i < length; i++) // encrypt characters one at a time
{
temp_char = OChars[i]; //
__asm { //
push eax
push ecx
lea eax, EKey
push temp_char
push eax
call encrypt21
mov temp_char, al
add esp, 8
pop ecx
pop eax
}
EChars[i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;
}
我希望得到一些关于如何将代码顶部的 for 循环更改为汇编语言的帮助,谢谢。
【问题讨论】:
-
你可以通过调试器简单的看反汇编代码(你也可以事先把你的整个代码改成C++,让编译器把它变成汇编)。
-
GCC 或 Clang 的
-S选项将为您提供生成的程序集。您可以使用它来确定如何在 x86 程序集中编写 for 循环。这种技术一般对学习汇编很有用,写一些C代码,让编译器教你怎么用asm写! -
您忘记包含 EChars 和 OChars 的声明。发布它们。