Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to convert the procedure encrypt_chars to assembler. I already have some x86 in assembly in the for loop, however I am trying to convert the remainder of the procedure into assembler. I'd be appreciative if you could help me

    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                  // 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                  //
        }
        EChars [i] = temp_char;         // Store encrypted char in the encrypted chars array
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
296 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...