Win32 compilation [22]-logic operation commands: And, Or, XOR, not, test

Source: Internet
Author: User
And: logic and
 
The command sets cf = of = 0. The result affects SF, ZF, and PF. Command Format: and R/m, R/M/I

  ; Test22_1.asm-use and to clear the second and fourth digits of a number. 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc mov Al, 11611b and Al, 11110101b printhex al; 05-00000101b retmain endpend main

  ; Test22_2.asm-use and to convert uppercase letters. 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data sztext dB 'delphi ', 0. codemain proc Lea ESI, sztext mov ECx, lengthof sztext-1: And byte PTR [esi], 11011111b; only the fifth digit of the upper and lower case letters is different from the inc esi loop @ B printstring sztext; Delphi retmain endpend main

  

Or: logical or

The command sets cf = of = 0. The result affects SF, ZF, and PF. Command Format: or R/m, R/M/I

  ; Test22_3.asm-use the or operation to ensure that the second and fourth bits of a number are 1.386.model flat and stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc mov Al, 11110001b or Al, 1271010b printhex al; FB-11111011b retmain endpend main

  ; Test22_4.asm-use or to convert letters to lowercase. 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data sztext dB 'delphi ', 0. codemain proc Lea ESI, sztext mov ECx, lengthof sztext-1: Or byte PTR [esi], 00100000b; only the fifth digit of the upper and lower case letters is different from the inc esi loop @ B printstring sztext; Delphi retmain endpend main

  

XOR: Logical exclusive or

The command sets cf = of = 0. The result affects SF, ZF, and PF. The command format is xor r/m, R/M/I.
  
   
 ; Test22_5.asm-restore the same number XOR to the original number twice. 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc mov eax, 12345 XOR eax, 88888888 printdec eax; 88892929 XOR eax, 88888888 printdec eax; 12345 retmain endpend main
  
   
 ; Test22_6.asm-use XOR to encrypt and decrypt strings. 386. Model flat, stdcallinclude windows. incinclude unzip masm32.incinclude Debug. incincludelib unzip masm32.libincludelib Debug. Lib. Data sztext dB 'Hello world! ', 0. codemain proc; encrypt Lea ESI, sztext mov ECx, lengthof sztext-1: XOR byte PTR [esi], 123; Use 123 as the password Inc ESI loop @ B printstring sztext; display garbled characters; decrypt Lea ESI, sztext mov ECx, lengthof sztext-1: XOR byte PTR [esi], 123 Inc ESI loop @ B printstring sztext; Hello world! Retmain endpend main
 
   
 

Not: Logical Inversion

 
; This command does not affect eflags; Command Format: Not r/m

  ; Test22_7.asm-use not to encrypt and decrypt strings. 386. Model flat, stdcallinclude windows. incinclude unzip masm32.incinclude Debug. incincludelib unzip masm32.libincludelib Debug. Lib. Data sztext dB 'Hello world! ', 0. codemain proc; encrypt Lea ESI, sztext mov ECx, lengthof sztext-1: Not byte PTR [esi] Inc ESI loop @ B printstring sztext; display garbled characters; decrypt Lea ESI, sztext mov ECx, lengthof sztext-1: Not byte PTR [esi] Inc ESI loop @ B printstring sztext; Hello world! Retmain endpend main

  

Test: Test logic and

The command sets cf = of = 0. The result affects SF, ZF, and PF. Command Format: Test R/m, R/M/I; test is the same as and, but it only changes the mark register without modifying the operation arithmetic, that is, the result of trying and. It is often used to influence ZF (ZF = 1 when the result is 0 ); after the test, the commands JZ and jnz are usually followed by the conditions.
  
   
 ; Test22_8.asm-observe the zero sign (ZF) after test ). 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc; Determine whether the last digit of the letter a binary (01000001) is 0. If it is 0, ZF = 1 mov Al, 'A' test Al, 00000001b lahf printhex Ah; 02-00000010b (ZF = 0); judge whether the last digit of the letter B binary (01000010) is 0. If it is 0, ZF = 1 mov Al, 'B' test Al, 20170001b lahf printhex Ah; 46-01000110b (ZF = 1); Determine whether ECx is null mov ECx, 1 test ECx, ECx lahf printhex Ah; 06-00000010b (ZF = 0, not blank) XOR ECx, ECx test ECx, ECx lahf printhex Ah; 06-01000110b (ZF = 1, null) retmain endpend main
  
   
 ; Test22_9.asm-judge whether the last binary digit of each character in the string is 1 or 0.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data sztext dB 'delphi ', 0. codemain proc; clear two registers for counting XOR eax, eax XOR edX, EDX Lea ESI, sztext; string address mov ECx, lengthof sztext-1; string length L1: test byte PTR [esi], 20170001b; test whether the last character of each character is 1 or 0 JZ L2; if it is 0, jump to L2 to edX + 1 Inc eax; otherwise, the eax + 1 JMP l3l2: Inc edxl3: Inc ESI loop L1 printdec eax; 2-this is the number of the last character to be 1: E, I printdec edX; 4-this is the number of the last 0 characters: D, L, P, H retmain endpend main
  
   
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.