基本上我要做的就是转换这块c ++& amp;组装成纯粹的汇编,我有点困惑如何将for循环和其余部分转换为汇编,如果有人能让我知道我哪里出错将会很棒。
这是原作
void encrypt_chars (int length, char EKey) // Encryption Function.
{ char temp_char; // Char temporary store.
for (int i = 0; i < length; i++) // Encrypt characters one at a time.
{
temp_char = OChars [i]; // Orignal Chars.
__asm { // Switch to inline assembly.
push eax
push ecx
movzx ecx,temp_char
push ecx
lea eax,EKey
push eax
call encrypt4 // Call the encryption subroutine
add esp, 8
mov temp_char,al
pop ecx
pop eax
}
EChars [i] = temp_char; // Store encrypted char in the encrypted chars array.
}
return;
然后,这是我尝试将c ++部分转换为汇编,这是我正在努力的事情,并希望得到一些指示 -
void encrypt_chars(int lengths, char EKey) // Encryption Function.
{
char temp_char;
__asm {
mov dword ptr[i], 0
jmp encrypt_chars
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
mov eax, dword ptr[i]
cmp eax, dword ptr[lengths]
jge encrypt_chars
mov eax, dword ptr[i]
mov cl, byte ptr[eax]
mov byte ptr[temp_char], cl
push eax
push ecx
movzx ecx,temp_char
push ecx
lea eax,EKey
push eax
call encrypt4 // Call the encryption subroutine
add esp, 8
mov temp_char,al
pop ecx
pop eax
mov eax, dword ptr[i]
mov cl, byte ptr[temp_char]
mov byte ptr[eax], cl
}
return;
答案 0 :(得分:1)
这是for循环的汇编示例:
mov R1, #5 ; This is the limit of the loop
mov R0, #0 ; R0 is the loop index, initialize the loop index variable.
loop:
cmp R0, R1 ; Part of the compare expression in for loop.
bge loop_exit;
;
; The statement block for the for loop.
inc R0 ; The increment part of the for loop
b loop ; Loop around to the compare part of the loop.
; First statement after the for loop
loop_exit: