Assembly language basics 4-Basic commands

Source: Internet
Author: User

Logic Operation commands

The following binary operations can be used:

Operator Meaning OperationAlgorithmThen
And And 0 & 0 = 0; 0 & 1 = 0; 1 & 0 = 0; 1 & 1 = 1
Or Or 0 | 0 = 0; 0 | 1 = 1; 1 | 0 = 1; 1 | 1 = 1
XOR Exclusive or 0 then 0 = 0; 0 then 1 = 1; 1 then 0 = 1; 1 then 1 = 0
Not Non ~ 0 = 1 ;~ 1 = 0

These are bitwise operations.

Note:

1 DWORD = 2 word = 4 byte = 32 bit

1 word = 2 byte = 16 Bit

1 byte = 8 bit

 

Arithmetic Operation commands

Add Add  
Sub Subtraction  
Mul Multiplication  
Div Division  
SHL Shift  
INC Add 1  
Dec Decrease 1  
Neg Complement Reverse lookup and add one more

 

Note:

The compiler generally combines these operations in a strange way, because it can achieve faster execution speed with the same results. Generally, the compiler compares complex commands to achieve faster execution speed. And the execution speed of all commands on different CPUs is different. Some of them can be done in one clock cycle, and some may be much better.

String command

Command Full name Command mnemonic Meaning
Rep Repeat Repeated It allows repeated execution of string commands (ECx is executed when it is not equal to 0). Each execution time, the content of ECx is reduced by 1.
Repe Repeat equal Equal and repeated When the two strings are equal, that is, ZF = 1, it can execute the string commands repeatedly (if ECx is not equal to 0). Each execution time, the content of ECx is reduced by 1. (Exactly the same as repz)
Repne Repeat not equal Not repeated When the two strings are not equal, that is, ZF = 0, it can execute the string commands repeatedly (if ECx is not equal to 0). Each execution time, the content of ECx is reduced by 1. (Exactly the same as repnz)
Movs Move string String Transmission Similar to movsb and movsw, but the data string type (word or byte) must be specified ).
Movsb Move string by byte Transmit strings by byte Transmit one byte of data in the data segment directed by ESI to a byte storage unit in the additional segment directed by EDI, and modify the addresses in ESI and EDI according to the direction signs. When df = 0, the address is added with 1; When df = 1, the address is reduced by 1.
Movsw Move string by word Send string by word Transmit a word term in the data segment directed by Si to a word storage unit in the additional segment directed by DI, and modify the address in Si and di according to the direction indicator. When df = 0, the address is added with 2; When df = 1, the address is reduced by 2.
CMPS Compare string String comparison Cmpsb or cmpsw is usually used.
Cmpsb Compare string by byte Byte comparison string Subtract the byte data specified by the DS segment Si from the byte data specified by the es segment di (the result is not saved), and then set the flag Based on the subtraction result (if the two data are equal, ZF = 1 ). And the direction signs DF to modify the address in Si and Di, that is, when df = 0, the address is added with 1; When df = 1, the address is reduced by 1.
Cmpsw Compare string by word Comparing strings by words Subtract the word data specified by Si in the DS segment from the word data specified by DI in the es segment (the result is not saved), and then set the flag Based on the subtraction result (if the two data are equal, ZF = 1 ). And the direction signs DF to modify the address in Si and Di, that is, when df = 0, the address is added with 2; When df = 1, the address is reduced by 2.
STOs Store Accumulator Storage Accumulators This command transfers the value in the accumulators to the memory specified by DS: Di. After the storage ends, the CPU either increases or reduces EDI, depending on the DF flag.
Lods Load Accumulator Load Accumulators The lods command is unique in string commands. You never need to use a duplicate prefix to modify the command. The lods Command copies the byte or word directed by DS: Si to Al, ax, or eax. After the copy is completed, the SI value is increased or decreased Based on the DF flag. Repeat this command does not make any sense. The value in eax will be continuously washed away, leaving only the last loaded value.
SCAs Scan string Scan string This command can be used to find a specific element in a string. The SCAs command only needs the address es: Di of the target string, instead of the Source and Destination strings. The value of the source string is in Al, ax, or eax.
This command compares the value pointed to by ES: di with the value (Al, ax, eax) in the accumulators, and then increases or decreases di 1, 2, or 4 According to DF.

Note:

The table above involves some of the Flag spaces in the sign register. For convenience, they are listed below:

ZF = zero flag, zero flag, and DF = Direction Flag;

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.