80 × 86 Command System

Source: Internet
Author: User

3.3 x86 Command System
3.3. 1 data transmission instructions

1. General transfer commands
(1) mov command
Format: mov DST, SRC
Function: Send the content of the source operand SRC to the destination operand DST.
(2) movsx signed extended transfer command (after 386)
Format: movsx DST, SRC
Function: (DST) compliant with the extension (SRC)
(3) movzx transfer instruction with zero extension (after 386)
Format: movzx DST, SRC
Function: (DST) Zero-Scaling (SRC)
Example 3.25 movzx dx, Al; 816
Example 3.26 movzx eax, data; 1632
(4) push into Stack command
Format: Push SRC
Function: 16-bit command: (SP) Second (SP)-2
(SP) + 1, (SP) extract (SRC)
32-bit command: (ESP) Quit (ESP)-4
(ESP) + 3, (ESP) + 2, (ESP) + 1, (ESP) (SRC)
(5) pop-out stack command
Format: Pop DST
Function: 16-bit command: (DST) Forward (SP) + 1, (SP ))
(SP) Forward (SP) + 2
32-bit command: (DST) (ESP) + 3, (ESP) + 2, (ESP) + 1, (ESP) + 4
(6) pusha/pushad all registers into the stack command (after 286)
Pusha: 16-bit stack order ax, CX, dx, BX, SP, BP, Si, Di before command execution. After execution (SP)-16.
Pushad: 32-bit stack order eax, ECx, EDX, EBX, ESP, EBP, ESI, and EDI before command execution. After execution (ESP)-32.
(7) All Popa/popad registers (after 286)
Popa: 16-bit output stack sequence: Di, Si, BP, SP, BX, dx, CX, ax.
After execution (SP) + 16.
Popad: 32-bit output stack sequence: Di, Si, BP, SP, BX, dx, CX, ax. After execution (ESP) + 16.
(8) xchg command
Format: xchg opr1, opr2
Function: Exchanges opr1 and opr2 operations.
The segment register and the number of segments are not allowed.
Example xchg BX, [bp + Si]
Before Execution (BX) = 6f30h, (BP) = 0200 h, (SI) = 0046 h, (SS) = 2f00h, (2f246h) = 4154 H
After execution (BX) = 4154 h, (2f246h) = 6f30h
2. Dedicated transfer commands of the Accumulators
(1) In input command
Long format: in Al, port (byte); (Al) (port)
In ax, port (Word); (ax) (Port + 1, Port)
In eax, port (dual); (eax) (Port + 3 ...)
Short format: in Al, (dx) (byte); (Al) (dx)
In ax, (dx) (Word); (ax) (dx + 1, dx)
In eax, (dx) (dual); (eax) (dx + 3 ...)
(2) Out output command
Long format: out port, Al (byte); (port) (Al)
Out port, ax (Word); (Port + 1, Port) (ax)
Out port, eax (dual); (Port + 3 ...) (Eax)
Example in ax, 28 h
MoV data-word, ax
Example mov dx, 3fch
In eax, DX
Example 5, Al
(3) xlat code change command
Format: xlat
Function: Send the content of the storage unit with the sum of Al and BX registers and the offset address to Al.
(Al) percentile (BX) + (Al); 16 bits
(Al) round (EBX) + (Al); 32-bit
Example 3.39 (BX) = 0040 h, (Al) = 0fh, (DS) = f000h,
(F004fh) = 2ch
After the command is executed (Al) = 2ch

3. Address Transfer command
(1) Lea command
Format: Lea Reg, Src; (REG) SRC
Function: Send the valid address of the source operand to the specified register.
Example 3.40 Lea BX, [bx + Si + 0f62h]
For example, before execution (BX) = 0400 h, (SI) = 003ch
After the command is executed (BX) = 0040 + 003c + 0f62 = 139eh
Example 3.41 Lea BX, list
MoV BX, offset list
(2) LDs, Les, LFS, LGS, and LSS pointer send registers and segment registers.
• LDs commands
Format: lDs Reg, Src; (REG) (SRC)
(DS) (SRC + 2)
Function: Send the four bytes of the SRC storage unit to the specified register and DS register.
Example 3.42 lDs Di, [BX]
For example, before execution (DS) = b000h, (BX) = 080ah, (0b080ah) = 05aeh,
(0b080ch) = 4000 H
After the command is executed (DI) = 05aeh, (DS) = 4000 H

4. Mark register transfer command
(1) The lahf flag sends the ah command
Format: lahf
Function: Send the rightmost 8 bits of the Mark register to the ah register.
(2) sahf Ah flag register instruction
Format: sahf
Function: Send the ah register content to the rightmost 8 bits of the Mark register.
(3) pushf/pushfd Mark into the stack command
Function:
Pushf :( SP) Forward (SP)-2
(SP) + 1, (SP) Submit (flags)
Pushfd :( ESP) (ESP)-4
(ESP) + 3, (ESP) + 2, (ESP) + 1, (ESP) (flags and 0 fcffffh)

(4) popf/popfd mark the stack command
Function:
Pushf :( flags) Forward (SP) + 1, (SP ))
(SP) Forward (SP) + 2
Pushfd :( flags) (ESP) + 3, (ESP) + 2, (ESP) + 1, (ESP ))
(ESP) + 4

5. type conversion commands
(1) Converting CBW bytes into word commands
Format: CBW
Function: expands the sign bit of Al to ah.
That is, if the sign bit of Al is 0, Ah = 00 h
If the sign bit of Al is 1, Ah = 0ffh
(2) CWD/cwde conversion to dual-word commands
Format: CWD
Function: expands the symbol bit of ax to DX.
That is, if the sign bit of ax is 0, dx = 0000 h
If the sign bit of ax is 1, dx = 0 ffffh
Format: cwde (later than 386)
Function: expands the symbol bit of ax to eax to form a dual word of eax.
(3) CDQ dual-word conversion to 4-byte commands
Format: CDQ (later than 386)
Function: expands the symbol bits of eax to edX to form four bytes of edX: eax.
(4) bswap byte switch command (after 386)
Format: bswap R32
Function: the byte order of the 32-bit Register specified by the instruction is reversed.
Case 3.44 bswap eax
Before Execution (eax) = 11223344 H
After execution (eax) = 44332211 H

1. commands matching rep

(1) repeated operation prefix
Format: rep <string operation command>
Function: 1) Exit the rep operation if Cx = 0; otherwise, go to 2) Execute
2) CX guest CX-1
3) execute the <string operation command> once after rep.
4) switch back 1) Execute

Note: 1) CLD clear direction flag command
Format: ClD
Function: DF defaults 0, which can automatically increase the address.
2) STD Direction Flag instruction
Format: std
Function: DF limit 1, which can automatically reduce the address.

(2) movs serial transmission commands
Format 1: movsb; byte operation
Function 1: Es :( di) ← DS :( Si ),
Si branch Si ± 1 di branch di ± 1
Format 2: movsw; Word operation
Function 2: Es :( di) ← DS :( Si ),
Si branch Si ± 2 di branch di ± 2

Example 3.70 Lea Si, mess1
Lea Di, mess2
MoV CX, 17
ClD
Rep movsb
(3) STOs storing string commands
Format 1: stosb; byte operation
Function 1: (DI) ← Al, di ← di ± 1
Format 2: stosw; Word operation
Function 2: (DI) ← ax, di ← di ± 2
Example 3.71 mov Al, 20 h
Lea Di, mes
MoV CX, 5
ClD
Rep stosb

(4) lods string READ command
Format 1: lodsb; byte operation
Function 1: Al proposal (SI) Si proposal Si ± 1
Format 2: lodsw; Word operation
Function 2: ax Branch (SI) Si branch Si ± 2

2. commands that match repe/repz and repne/repnz

(1) repeated operation prefix when repe/repz is equal (0)
Format: repe/rpez <string operation command>
Function: 1) Exit repe/repz if (CX) = 0 or ZF = 0,
Otherwise, go to step 2. Execute
2) (CX) Compute (CX)-1
3) execute the subsequent string commands
4) Repeat 1 )~ 3)

(2) repeated operation prefix when repne/repnz is not equal (not 0)
Format: repne/rpenz <string operation command>
Function: 1) if (CX) = 0 or ZF = 1, exit repne/repnz; otherwise, go to 2)
2) (CX) Compute (CX)-1
3) execute the subsequent string commands
4) switch back 1) Execute

Note:
1) Si is used as the source string address pointer and Di is used as the destination string address pointer.
If the repeated prefix rep is used, the length of the string must be stored in the Cx register.
2) determine the appropriate DF value based on the actual situation,
The add address method sets df = 0, and the remove address method sets df = 1.
3) The source string is in the data segment, and the target string is in the additional segment.
You can also define the source string and target string in a physical segment as both a data segment and an additional segment.

(3) CMPs string comparison command

Format 1: cmpsb; byte operation
Function 1: (DI)-(SI), Si ← Si ± 1, di ← di ± 1
Format 2: cmpsw; Word operation
Function 2: (DI)-(SI), Si ← Si ± 2, di ← di ± 2

2) SCAs string scan command
Format 1: scasb; byte operation
Function 1: Al-(DI), di ← di ± 1
Format 2: scasw; Word operation
Function 2: ax-(DI), di ← di ± 2

Example 3.72 mov Al, 20 h
Lea Di, mes; (DI) = 1500 h, P83
MoV CX, 11 h
ClD
Repnz scasb; (CX) = 8, (DI) = 1509 H
Example 3.73 Lea Si, mes1; 1500 h
Lea Di, mes2; 0200 H
MoV CX, 11 h
ClD
Repe cmpsb
; (SI) = 1505 h, (DI) = 0205 h, (CX) = 0ch, ZF = 0. See p84

3.3.5 processor control commands and Miscellaneous Operation commands
1. Mark Processing Command
• CLC carry position 0 command CF defaults 0
• CMC carry position 0 command CF highlight/CF
• STC carry position 1 command CF Highlight 1
• Set the CLD Direction Flag to 0 command DF limit 0
• STD Direction Flag sets 1 command DF limit 1
• Set the CLI interrupt flag to 0 command if interrupt 0
• The STI interrupt flag sets the I command if interrupt 1

2. Other processor control commands and Miscellaneous Operation commands
• NOP null Operation Command
This command does not perform any operations
• Hlt shutdown command; CPU Shutdown
3.2.3 logic operation commands

1. Logic Operation commands

(1) and logic and commands
Command Format: and DST, Src; (DST) hour (SRC)
Command function: Perform logical "and" operations on the source and target operands in bits, and send the results to the target operands.

(2) or logic or command
Command Format: or DST, Src; (DST) hour (SRC)
Command function: Perform logical "or" operations on the source and target operands in bits, and send the results to the target operands.

(3) not logical non-directive
Command Format: Not OPR; (OPR) province/(OPR)
Command: returns the bitwise result of a given operand.

(4) XOR logic exception or command
Command Format: xor dst, Src; (DST) hour (SRC)
Command function: the source and target operands are operated in the bitwise way and the result is sent to the target operand.

(5) test commands
Command Format: Test opr1, opr2; (opr1) Example (opr2)
Command function: Perform logical "and" operations on two operands by bit, but do not save the result. Only set the status bit based on the feature.

Example 3.57 mov Al, 0bfh
And Al, 0fch; mask 0 and 1 bits.
Example 3.58 mov Al, 43 H
Or Al, 20 H; 1, 5th.
Example 3.59 mov Al, 40 h
Test Al, 0afh
; Test 0, ZF = 1
Example 3.60 mov DL, Al
Not DL
Test DL, 00000100b
To test whether the value of Al 2nd bits is 1.
Example 3.61 mov Al, 11 h
XOR 3; the first and second digits are reversed.
Example 3.62 XOR ax, 042eh
; Test AX = 042eh? For example, ZF = 1 is equal.

4. Shift command

(1) shift instruction

1) SHL logic left shift command
Command Format: SHL opr, CNT
Command function: shifts the specified operand to the left CNT bit, and moves the highest bit to the carry bit cf at each time. The empty seek bit is supplemented by 0. 8086 cpu cnt can be 1 or Cl.

2) Sal arithmetic left shift command
Command Format: Sal opr, CNT
Command function: identical to SHL command.

3) SHR logic right shift command
Command Format: SHR opr, CNT
Command function: shifts the specified operand to the right CNT bit. Each time the forward bit is moved to the carry bit CF, the maximum bit of the blank out is 0.

4) SAR arithmetic right shift instruction
Command Format: SAR opr, CNT
Command function: shifts the specified operand to the right CNT bit. Each time the forward bit is moved to the carry bit CF, the highest bit of the empty output keeps its original value.

(2) cyclic shift command

1) ROL loop left shift command
Command Format: ROL opr, CNT
Command function: shifts the left ring of the specified operand to CNT bits. Each time the highest bits are moved to the carry bits CF, the other bits are shifted to the left, and the empty seek bits are filled by the original highest bits.

2) ror loop right shift command
Command Format: ror opr, CNT
Command function: shifts the right ring of the specified operand to CNT bits. Each time the forward bits are moved to the carry bits CF, the other bits are shifted to the right, and the highest bits of the empty bits are filled in by the original forward bits.

3) RCL instructions for bringing a bitwise loop left shift
Command Format: RCL opr, CNT
Command function: shifts the specified operand to the left ring along with the carry bit. For each shift, CF is moved to the lowest Bit Of the operand, the highest bit of the operand is moved to CF, And the other bits are shifted to the first bit.

4) RCR in-bit loop shift right instruction
Command Format: RCR opr, CNT
Command function: shifts the specified operand along with the carry bit to the right ring. For each shift, CF is moved to the highest bit of the operand. The forward bit of the operand is moved to CF, And the other bits are shifted to the right.

Example 3.65 mov Cl, 5
SAR [di], Cl
Before Execution (DS) = 0f800h, (DI) = 180ah,
(0f980ah) = 0064 H
After execution (0f980ah) = 0003 H, cf = 0; 100/32 = 3
Example 3.66 mov Cl, 2
SHL Si, Cl
Before Execution (SI) = 1450 H
After execution (SI) = 5140 H, cf = 0; 5200*4 = 20800
Example 3.67 mov Cl, 8
Rol ax, Cl
Add ax, BX
Before Execution (ax) = 0012 h, (BX) = 0034 H
After the execution (ax) = 1234 H
3.3.2 arithmetic commands
1. Addition command
(1) Add addition command
Format: Add DST, Src; (DST) values (SRC) + (DST)
Function: adds the source and target operands as two binary numbers,
And sends the result to the target operand.
(2) ADC incoming bit addition command
Format: adc dst, Src; (DST) release (SRC) + (DST) + CF
Function: adds the source, target, and inbound CF values and sends them to the target operations.
(3) INC plus 1 command
Format: Inc OPR; (OPR) Branch (OPR) + 1
Function: Add 1 to the content of any register or storage unit except the segment register.
Example 3.45 add dx, 0f0f0h
Before Execution (dx) = 4652 H
After execution (dx) = 3742 H, ZF = 0, Sf = 0, cf = 1, of = 0
Example 3.46 add ax, CX
ADC dx, BX
Before Execution (dx) = 0002 h, (ax) = 0f365h,
(BX) = 0005 h, (CX) = 0e024 H
(Dx) = 0008 h, (ax) = 0d389h
2. subtraction commands
(1) Sub subtraction command
Format: Sub DST, Src; (DST) hour (DST)-(SRC)
Function: subtract the source operand from the target operand and save the result to the target operand.
(2) SBB subtraction command with borrow digits
Format: sbb dst, Src; (DST) hour (DST)-(SRC)-cf
Function: subtract the source operand from the target operand, then subtract the borrow CF, and save the result to the target operand.
(3) DEC minus 1 command; (OPR) minus (OPR)-1
Format: Dec OPR
Function: Subtract 1 from the target operand.

(4) neg complement command
Format: neg OPR; (OPR) percentile 10000 h-(OPR); 16 bits
Function: returns the result to the target operand by adding 1 to the bitwise result.

(5) CMP comparison command
Format: CMP opr1, opr2; (opr1)-(opr2)
Function: subtract the source operand from the target operand, but do not return the result to the target operand. Set the flag based on the result.
Example 3.48 sub [Si + 14 h], 0136 H
Before Execution (DS) = 3000 h, (SI) = 0040 H,
(30054 H) = 4336 H,
After execution (30054 H) = 4200 H, Sf = 0, ZF = 0, cf = 0, of = 0
Example 3.49 sub DH, [bp + 4]
Before Execution (DH) = 41 h, (SS) = 0000 h, (BP) = 00e4h,
(000e8h) = 5ah
After execution (DH) = 0e7h, Sf = 1, ZF = 0, cf = 1, of = 0
For example, 3.50 w running X + Y + 24-z; 32 bits are completed with 16 bits.
MoV ax, X
MoV dx, x + 2
Add ax, y
ADC dx, Y + 2
Add ax, 24
ADC dx, 0
Sub ax, Z
SBB dx, Z + 2
MoV W, ax
MoV W + 2, DX
3. Multiplication command
(1) Mul command for multiplying the number of unsigned numbers
Format: Mul SRC; byte: (ax) encrypt (Al) * (SRC)
(Dx, ax) least (ax) * (SRC)
Function: multiply the accumulators (ax or Al) with the source operand as an unsigned number.
Byte operation: the results of Al x SRC are stored in ax.
Word operation: the result of ax x SRC is stored in dxax.

(2) imul signed number multiplication command
Format: imul SRC
Function: multiply the accumulators (ax or Al) with the source operand as a signed number.
Byte operation: the results of Al x SRC are stored in ax.
Word operation: the result of ax x SRC is stored in dxax.
Example 3.52 (Al) = 0b4h, (BL) = 11 h
Mul BL result (ax) = 0bf4h = 3060d, cf = of = 1
Imul BL result (ax) = 0faf4h =-1292d, cf = of = 1
4. Division commands
(1) Div unsigned number division command
Format: div SRC;
Byte :( Al) operator (ax)/(SRC)
(AH) remainder of least (ax)/(SRC)
Word: (ax) operator (dx, ax)/(SRC)
(Dx) remainder of values (dx, ax)/(SRC)
Function: division two unsigned numbers.
Byte computation: The result provider of ax merge SRC is in Al, and the remainder is in AH.
Word operation: dxax has SRC result provider in ax and remainder in dx.
(2) idiv number division command
Format: idiv SRC
Function: Division Two signed numbers.
Example 3.55 (ax) = 0400 h, (BL) = 0b4h
Div BL
; Result provider (Al) = 05, remainder (AH) = 7ch = 124d
Imul BL
; Result provider (Al) = 0f3 =-13, remainder (AH) = 24 h = 36D
Example 3.56
3.2.3 decimal Arithmetic Operation Command
1. Compressed BCD code Adjustment Command
• Decimal Adjustment Command for DAA Addition
Format: daa
Function: used after adding two compressed BCD codes, the implicit Al is the target operand.
MoV Al, 17 h
Add Al, 18 h
DAA
• Decimal Adjustment Command for DAS Subtraction
Format: Das
Function: this function is used after two compressed BCD codes are subtracted, and the hidden Al is the target operand.
2. Non-compressed BCD code Adjustment Command
• ASCII code Adjustment Command for AAA Addition
Format: AAA
Function: used after adding two non-compressed BCD codes, the implicit Al is the target operand.
• ASCII Adjustment Command for AAS Subtraction
Format: AAS
Function: this function is used after two non-compressed BCD codes are subtracted, and the hidden Al is the target operand.
• AAM multiplication ASCII code Adjustment Command
Format: AAM
Function: this function is used after two non-compressed BCD codes are multiplied. The implicit source operand is Al, and the target operand is ax.
• Aad division ASCII code Adjustment Command
Format: aad
Function: adjusts non-compressed BCD codes in ax to binary values and sends them to Al as the divisor.

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.