如何在C ++来汇编循环转换? [英] How to convert for loop in c++ to assembler?

查看:215
本文介绍了如何在C ++来汇编循环转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想程序encrypt_chars转换为汇编。我已经在装配在for循环的一些x86的,但是我想在程序的剩余部分转换成汇编。我会AP preciative如果你能帮助我。

 无效encrypt_chars(INT长度,字符EKEY)
{字符temp_char; //字符临时存储    的for(int i = 0; I<长度;我++)//一次加密的人物之一
    {
        temp_char = OChars [I] //
        __asm​​ {//
            推EAX //保存堆栈寄存器值是安全的
            推ECX //
                                        //
            MOVZX ECX,temp_char //设置寄存器(注:这不是STDCALL或CDECL)
            LEA EAX,EKEY //
            调用encrypt12 //加密字符
            MOV temp_char,人//
                                        //
            流行ECX //从堆栈恢复原来的寄存器值
            弹出EAX //
        }
        EChars [I] = temp_char; //加密字符数组中存储加密的CHAR
    }


解决方案

接下来是code为作为控制变量为语句转换成汇编,注册EDI我,如果EDI是被通过encrypt21改变,就在推后的号召encrypt21,以$ p $弹出它pserve,恢复它的价值。我所说的LEN更改参数长度因为这个名字给我的问题:

 无效encrypt_chars(INT LEN,焦易科)
{字符temp_char;__asm​​ {MOV EDI,0;对于(EDI = 0;        法院地法:        ;获取当前CHAR。          MOV人,OChars [EDI]
          MOV temp_char,人        ; ENCRYPT CURRENT CHAR。          推EAX //保存堆栈寄存器值是安全的
          推ECX
          MOVZX ECX,temp_char //设置寄存器(注:这不是STDCALL或CDECL)
          LEA EAX,EKEY
          调用encrypt12 //加密字符
          MOV temp_char,人
          流行ECX //从堆栈恢复原来的寄存器值
          流行EAX       ;存储加密的CHAR。          MOV人,temp_char
          MOV EChars [EDI],人       ;对于声明:(EDI = 0;&EDI LT; LEN,EDI ++)          INC EDI; EDI ++。
          CMP EDI,LEN
          JB法院地法; IF(EDI< LEN)跳转。
      }
返回;
}

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
    }

解决方案

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

这篇关于如何在C ++来汇编循环转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆