Skills "c"

A, logical operators

  1, or operation (|| C language) 

    Conditions Masakazu 假: 

       Non-zero is true zero false

    ++ is + (false false false)

    Truncated principle if (a || b) to determine whether the previous is true, the thought may be on the front row of large

    c = i || j;

    if (c) {}

    See assembly instructions

    /*

009E1014 |. C745 FC 330> mov [local.1], 0x33
009E101B |. C745 660 F4> mov [local.3], 0x66
009E1022 |. 837D FC 00 cmp [local.1], 0x0
009E1026 |. 75 0F jnz short compilation .009E1037 // jnz not Skip due 0 0 1 local-less and jump to 0, resulting in no second parameter is determined, the efficiency of fast

009E1028 |. 837D F4 00 cmp [local.3], 0x0 // If 0 does not jump, the comparison continues with the second parameter (false false false)

009E102C |. 75 09 jnz short compilation .009E1037
009E102E |. C745 F0 000> mov [local.4], 0x0
009E1035 |. EB 07 jmp Short compilation .009E103E
009E1037 |> C745 F0 010> mov [local.4], 0x1
009E103E |> 8B45 F0 mov eax, [local.4]; compilation .envpcurity_cookie_complement
009E1041 | 8945 F8 mov [local.2], eax.
009E1044 | 8BC0 mov eax, eax.

     */

  

  2, Bitwise or (c language |)  

      0x33 ==>>   00 11 00 11

    | 0x66         + 01 10 01 10

       = 0x77 ==> = 01 11 01 11 (false false false) 

    /*

009E1046 |. 8B4D FC mov ecx,[local.1] ; msvcr100.72AD266D
009E1049 |. 0B4D F4 or ecx,[local.3]
009E104C |. 894D F8 mov [local.2],ecx ; msvcr100.__initenv

    */

    Use or compilation directive 

   3, the operation

    == >> logic (&& c language)

        Barbara is true

      c = a && b // your code is considered a false front. Determine whether the false front, the thought may be on the front row of large

      if ( c ){}

      Truncated principle

    == >> Bitwise AND (c & language)

      0x33 ==>>    00 11 00 11

    & 0x66         + 01 10 01 10

       = 0x22 ==> = 00 10 0010 (Barbara is true) 

    /*

  4, non-operational

    (1) Logical negation (c language!)

       False becomes true, true becomes false

      sete (setz) takes a value stored in the flag ZF

      setne (setnz) ZF flag value stored negated

      (2) bitwise (c ~ language)

        

    c language code in assembler instruction

      #include <cstdio>
      int main(){
      printf("fsadfasd");
      int i, j;
      i = 0x7787;
      j =  !i ; // 0

      /*

      

      */

      __asm mov eax, eax
      j = ~i;

          

 

 

 


      return 0;

      }

       NOT instruction

 

   5, an exclusive OR operation

     (1) bitwise exclusive or (c language ^)

      1 ^ 1 = 0, 0 ^ 0 = 0, 0 is the same

      0 1 = 1 ^, 1 ^ 0 = 1, 1 is different from

      eg :   1101

          ^ 0110

         = 1011  

      

 

 

 

      Classic exercises:

        (1) without the aid of a third variable, the two exchanging data (a large number of values ​​there will be problems, overflow)

            int a = 5, b = 7;

            a = a+b;   // a = 12

            b = a - b;  // b = 12 - 7 = 5

            a = a - b;  // a = 12 - 5 = 7

        (2) Efficient XOR

          

 

    Logical operation instructions are summarized:

       (1) or: bitwise OR operation, false false false (1, 1, 0 0 full)

          Such as: 101100

           |   110101

           =  111101

       (2) and: bitwise AND, Barbara true (0 0, 1 1 full)

          Such as: 101100

           &   110101

           =   100100

       (3) Not: Invert operation

          Such as: not 1011

              =   0100

        (4) xor: exclusive-OR operation (the same is 0, 1 is different)

          Such as: 101100

            ^  110101

            =  011001

                  

Second, the operation related command character

  1, a string comparison function strcmp disassembly Analysis:

  2, REPNE instructions and SCASB

    (1) SCASB instructions:

      SCASB compiled:

        SCASB BTYP PTR ES: [Eddie] char s1 [0] byte 1  

        //// SCASW WORD PTR [EDI]      short  s1[0]  word  2

        //// SCASD  DWORD PTR [EDI]   int      s1[0]   dword 4

      Equivalent to

        cmp byte prt [edi], al

       Effect flag corresponds SUB instruction, while also modifying the value of the register EDI

        If the DF flag is 0, inc EDI

        Otherwise, dec EDI

      

    (2) REPNE instruction (continuously performed)

        repnz scasb compiled: repne scas bype ptr es: [edi]

        When ecx = 0 and ZF = 0, the instruction is repeatedly performed back scas bype ptr es:! [Edi]

        Each execution of a secondary EDI value plus 1, minus the value of ECX 1

        

         // This assembly code is to obtain the length of the characters (mainly to achieve a logical thought)

        repne and repnz different mnemonic of the same instruction

  3, REPE / REPZ and CMPSB, CMPSW, CMPSD instruction

    (1)CMPS

        PBMCs byte ptr [edi], byte ptr [esi]

        PBMCs word ptr [edi], byte ptr [esi]

        PBMCs dword ptr [edi], byte ptr [esi]

        Effect of sub flag corresponds to instruction, and also modifies the value of the register EDI and ESI

          If the DF flag is 0, EDI, ESI press relative to the size (byte, word, dword) is incremented

          If the DF flag is 1, the EDI, ESI press relative to the size (byte word dword) decreasing

    (2) REPE / REPZ

        repe / repz cmpsb when ecx! = 0 and zf = 1, the following instruction is repeatedly executed

        Each time ecx decremented by 1

    (3) Examples of use

        比较串是否相等

        

      (4)汇编编写字符串比较函数

         (1)asm_strcmp 函数

            _declspec(naked)  告诉编译器用纯汇编方式编译函数, 不自动添加

                      寄存器保护和堆栈平衡代码

         (2)STD/CLD指令(DF方向标志位相关)

            std   df = 1

            cld   df =  0

 三、串存储和串的加载指令

    (1)串存储指令STOSB、STOSW、STOSD

        STOSB  STOS BYTE PTR [EDI]

        STOSW  STOS WORD PTR [EDI]

        STOSD  STOS  DWORD PTR [EDI]

        相当于:

          mov byte    ptr [edi], al

          mov word   ptr [edi], ax

          mov dword ptr [edi], eax

          rep stosb    rep stos byte ptr [edi]

          用al 的值 填充byte ptr [edi],每次ecx值减1,edi加1

     定位main()函数位置的步骤:

      第一步:打开程序, 程序启动后停在这里,直接jmp跳转

      第二步:jmp跳转跟随之后, 找到call  dword ptr [<xxxxx.exit>]退出的代码的位置

      第三步:call dword ptr [<xxxxx.exit >] 前一个call就是main函数。

    (2) 串载入指令LODSB, LODSW,LODSD

      lodsb lods byte ptr [esi]

      lodsw lods woedptr [esi]

      lodsd lods dword ptr [esi]

      

     rep lodsb ==>> rep lods byte ptr [esi]

     用byte ptr [esi]  的值, 填充al, 每次ecx值减1 , esi的值加1

      

  

 

    

 

        

 

      

           

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

       

 

Guess you like

Origin www.cnblogs.com/helloboke/p/11588229.html