Next is the code for the "for" statement converted into assembler, register EDI is used as the control variable "i", if EDI is been changed by "encrypt21", just push it before and pop it after "call encrypt21" to preserve-restore its value. I changed the parameter "length" by "len" because the name gave me problems :
void encrypt_chars(int len, char EKey)
{ char temp_char;
__asm { mov edi, 0 ;FOR ( EDI = 0;
fori:
;GET CURRENT CHAR.
mov al, OChars[edi]
mov temp_char, al
;ENCRYPT CURRENT CHAR.
push eax // save register values on stack to be safe
push ecx
movzx ecx,temp_char // set up registers (Nb this isn't StdCall or Cdecl)
lea eax,EKey
call encrypt12 // encrypt the character
mov temp_char,al
pop ecx // restore original register values from stack
pop eax
;STORE ENCRYPTED CHAR.
mov al, temp_char
mov EChars[ edi ], al
;FOR STATEMENT : FOR ( EDI = 0; EDI < LEN, EDI++ )
inc edi ;EDI++.
cmp edi, len
jb fori ;IF ( EDI < LEN ) JUMP.
}
return;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…