8086 assembly instruction summary, 8086 assembly instruction

Source: Internet
Author: User

8086 assembly instruction summary, 8086 assembly instruction

After learning, we have summarized the Common commands in 8086 Assembly as follows:

(1). mov: move data

For example:

Mov ax, 8 h; mov register, constant mov ax, bx; mov register, register mov ax, ds: [0]; mov register, memory unit mov ds: [0], ax; mov memory unit, register mov ds, ax; mov segment register, register mov word ptr ds: [0], 8 h; mov (memory unit size statement) memory unit, constant sk: mov ax, offset sk; mov register, label offset address mov byte ptr ds: [0], offset sk; mov memory unit, label offset address

Easy to troubleshoot:

Mov ds: [0], ds: [1]; mov memory unit, memory unit (invalid command) mov ds, 8 h; mov segment register, constant (invalid command) mov ds, es; mov segment register, segment register (invalid instruction) mov ds, offset sk; mov segment register, label offset address (invalid instruction) mov [0], ax; the constant offset address cannot be omitted. The default ds address must be declared as a segment address (invalid command)


(2). add: add a data value. The usage is similar to that of mov.

(3). sub: reduce the data value. The usage is similar to that of mov.


(4). push: in the stack, the top pointer of the stack (sp) = (sp) + 2, and a word of data is stored in the memory unit specified by the sp

For example:

Push ax; push register push ds: [0]; push memory unit
Easy to troubleshoot:

Push al; push register (high/low) byte (invalid command), must be a word, 16-Bit Data push 8 h; push constant (invalid command)

(5). pop: read out the stack, read the memory unit indicated by the word sp, and make the stack top pointer (sp) = (sp)-2

For example:

Pop ax; pop register pop ds: [0]; pop memory unit

Easy to troubleshoot:

Pop al; pop register (high/low) byte (invalid command), must be a word, 16-Bit Data pop 8 h; pop constant (invalid command)

(6). inc: data value + 1, dec: data value-1

For example:

Inc ax; inc register inc byte ptr ds: [0]; inc (size statement) memory unit dec ax; dec register dec byte ptr ds: [0]; dec (size statement) memory Unit

Easy to troubleshoot:

Inc 8 h; inc constant (invalid command) dec 8 h; dec constant (invalid command)

(7). jmp: unconditional transfer instruction

For example:

S: jmp short s; short transfer within a segment, jmp short label, IP modification range-128 ~ 127 jmp near ptr s; intra-segment near transfer, jmp near ptr label, IP modification range-32768 ~ 32767; the essence of the above two commands is to save the offset distance from the IP address to the label. Pay attention to the correct use of jmp far ptr s; Inter-segment transfer (Remote transfer), jmp far ptr s, modify CS: segment address marked by IP Address: Offset address jmp ax; intra-segment transfer, jmp 16-bit reg, (IP) = (16-bit reg) jmp word ptr ds: [0]; intra-segment transfer, jmp word ptr memory unit address,; (IP) = (two-byte memory in the memory unit address) jmp dword ptr ds: [0]; Inter-segment transfer, jmp dword ptr memory unit address; (IP) = (16-Bit Memory Data at the memory unit address), (CS) = (16-Bit Memory Data at the memory unit address)

Easy to troubleshoot:

Jmp 1000:0; want to transfer to (cs: ip) = (1000:0) (illegal command) jmp offset s; want to transfer to label s (illegal command)

(8). jcxz: conditional transfer instruction, equivalent
If (cx) = 0) jmp short label;


(9). loop: loop command, equivalent

(Cx) --; if (cx )! = 0) jmp short label;

(10). and: Binary and operation, similar to mov, add, and sub operations

(11). or: binary or operation, similar to mov, add, and sub operations

For example:

And ds: [0], 1111 h; and memory unit and ax, 1111 h; and 16-bit register constant and al, 11111110b; and 8-bit register constants (0th bits are set to 0) and ax, bx; and 16-bit registers, 16-bit registers; and so on... or ds: [0], 1111 h; or memory unit or ax, 1111 h; or 16-bit register constant or al, 100000001b; or 8-bit register constants (0th bits are set to 0) or ax, bx; or 16-bit registers, 16-bit registers; and so on...

(12). mul: Multiplication command

; (1) Two multiplied numbers: the two multiplied numbers are either 8 bits or 16 bits. If it is 8 bits, one is put in AL by default, and the other is put in 8 bits reg or memory byte units; if it is 16 bits, the other is in; AX by default, the other is placed in a 16-bit reg or memory unit .; (2) Result: if it is an 8-bit multiplication, the result is put in AX by default; if it is a 16-bit multiplication, the result is saved in high by default; DX is saved, and the low value is put in AX .; Calculate 100*10 mov al, 100 mov bl, 10 mul bl; Result: (ax) = 1000 (03E8h); Calculate 100 * 1_mov ax, 100 mov bx, 10000 mul bx; result: (ax) = 4240 H, (dx) = 000FH (F4240H = 1000000)

(13). div: division command

; Divisor: there are two types: 8-bit and 16-bit, in a reg or memory unit; divisor: it is placed in AX, DX, and AX by default. If the divisor is 8-bit, the divisor is 16 bits, and is stored in AX by default. If the divisor is 16 bits and the divisor is 32 bits, it is stored in DX and AX, DX is saved, and 16 bits are raised, AX stores 16 bits low. Result: If the divisor is 8 bits, AL stores the remainder of the operation unless the operator, AH stores the remainder of the operation; if the divisor is 16 bits, then, AX stores the Division operator, DX stores the remainder of the division operation, and calculates 100001/100 mov dx, 1 mov ax, 86A1H; (dx) * 10000 H + (ax) = 100001 mov bx, 100 div bx; Result: (ax) = 03E8H (1000), (dx) = 1 (the remainder is 1); Calculate 1001/100 mov ax, 1001 mov bl, 100 div bx; Result: (al) = 0AH (10), (ah) = 1 (the remainder is 1)

(14) call number: equivalent

Push IP jmp near ptr label

(15) ret: equivalent

pop IP
Therefore, it is often used in this way:

call program1program1: ;........ret

(16) call far ptr number: equivalent

Push CSpush IP jmp far ptr label

(17). retf: equivalent

pop IP pop CS
Therefore, it is often used in this way:

call far ptr program2program2: ;........retf

(18) call word ptr memory address: equivalent

Push IP jmp word ptr memory address; for example, mov sp, 10 h mov ax, 0123 h mov ds: [0], ax call word ptr ds: [0]; results: (IP) = 0123 H, (SP) = 0EH

(19) call dword ptr memory address: equivalent

Push CS push IP jmp dword ptr memory unit address; for example, mov sp, 10 h mov ax, 0123 h mov ds: [0], ax mov word ptr ds: [2], 0 call dword ptr ds: [0]; Result: (CS) = 0, (IP) = 0123 H, (sp) = 0CH

(20) shl: logic left shift command

; (1) shift the data in a register or memory unit to the left; (2) write the last removed data to CF; (3) Fill the second BIT with 0; for example: mov al, 01001000b shl al, 1; Result: (al) = 10010000b, CF = 0; if the number of digits to be moved is greater than 1, the number of digits to be moved must be placed in cl mov al, 01010001 bmov cl, 3 shl al, cl; Result: (al) = 10001000b. Because the last bit to be removed is 0, CF = 0


(21) shr: Logical right shift command

; (1) shift the data in a register or memory unit to the right; (2) write the last removed data to CF; (3) Add the highest bit to 0; for example: mov al, 0000001b shr al, 1; Result: (al) = 0000000b, CF = 0; if the number of digits to be moved is greater than 1, the number of digits to be moved must be placed in cl mov al, 01010001 bmov cl, 3 shr al, cl; Result: (al) = 20171010b. Because the last bit to be removed is 0, CF = 0

(22) int constant: Interrupt Routine


Summary:

From the above, we can see that the 8086 assembly has the following syntax rules:

(1) There are three types of commands:

Command target source

Command target

Command

(2) except the int command, the "target" cannot be a constant.

(3) When "target" is a segment register, "Source" can only be a register

(4) The memory size occupied by the "target" and "Source" should be the same,

When the two sides explicitly know the size of memory bytes, if not the same, it cannot be compiled,

If only one party knows the size of the memory byte, data processing is calculated based on the size of the memory byte of the party,

When neither side knows the size of the memory byte, The byte/word/dword ptr display statement is applied. dword ptr is only used for some special commands.

(5) There are two types of transfer instructions: Direct setting and displacement offset, where the displacement offset has a distance limit.






8086 and 8088 assembly instructions

8086/8088 Command System
I. Data Transmission instructions
1. General Data Transmission commands
MOV (Move) Transfer
PUSH (Push onto the stack) to stack
POP (Pop from the stack)
XCHG (Exchange) Exchange
. MOV command
Format: mov dst, SRC
Operation: (DST) <-(SRC)
. PUSH to stack command
Format: PUSH SRC
Operation: (SP) <-(SP)-2
(SP) + 1, (SP) <-(SRC)
. POP output stack command
Format: POP DST
Operation: (DST) <-(SP + 1), (SP ))
(SP) <-(SP) + 2
. XCHG switch command
Format: XCHG OPR1, OPR2
Operation: (OPR1) <--> (OPR2)
2. Dedicated transfer commands of the Accumulators
IN (Input) Input
OUT (Output) Output
XLAT (Translate) for code
This set of commands is limited to transmitting information using the accumulators AX or AL.
. IN input command
Long format: in al, PORT (bytes)
In ax, PORT (word)
Operation: (AL) <-(PORT) (byte)
(AX) <-(PORT + 1, PORT) (word)
Short format: in al, DX (bytes)
In ax, DX)
Operation: AL <-(DX) (bytes)
AX <-(DX) + 1, DX) (word)
. OUT output command
Long format: out port, AL (bytes)
Out port, AX (word)
Operation: (PORT) <-(AL) (bytes)
(PORT + 1, PORT) <-(AX) (word)
Short format: out dx, AL (bytes)
Out dx, AX (word)
Operation: (DX) <-(AL) (bytes)
(DX) + 1, (DX) <-AX (word)
On a IBM-PC machine, an external device can have a maximum of 65536 I/O Ports (that is, the peripheral port address) is
0000 ~ FFFFH. The first 256 ports (0 ~ FFH) can be specified directly in the command. This is the PORT in the long format.
The machine command is expressed in two bytes, and the second byte is the port number. Therefore, you can directly specify
Port number, but only the first 256 ports are allowed. When the port number is greater than or equal to 256, only the short format can be used.
IN the DX register (the port number can be from 0000 to 0 FFFFH), and then the IN or OUT command is used to transmit information.
. XLAT code change command
Format: XLAT OPR
Or: XLAT
Operation: (AL) <-(BX) + (AL ))
3. Send register instruction to a valid address
LEA (Load Balancing tive address) valid address send register
LDS (Load DS with Pointer) Pointer send register and DS
LES (Load ES with Pointer) Pointer to send registers and ES
. LEA valid address sending register
Format: lea reg, SRC
Operation: (REG) <-SRC
The Command sends the valid address of the source operand to the specified register.
. LDS pointer to send registers and DS commands
Format: lds reg, SRC
Operation: (REG) <-(SRC)
(DS) <-(SRC + 2)
Sends the four successive bytes specified by the source operand to the registers and DS registers specified by the instruction.
SI register.
. LES pointer to send registers and ES commands
Format: les reg, SRC
Operation: (REG) <-(SRC)
(ES) <-(SRC +... the remaining full text>

8086 and 8088 assembly instructions

I. Data Transmission instructions

They transmit data between the storage and registers, registers, and input/output ports.
1. General Data Transmission commands.
MOV transfers words or bytes.
MOVSX first extends the symbol and then transmits it.
MOVZX is not extended before transmission.
PUSH pushes words into the stack.
POP pops up the word stack.
PUSHA pushes AX, CX, DX, BX, SP, BP, SI, DI into the stack in sequence.
POPA pops up the stack of DI, SI, BP, SP, BX, DX, CX, and AX in sequence.
PUSHAD pushes EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI to the stack in sequence.
POPAD pops up the stacks of EDI, ESI, EBP, ESP, EBX, EDX, ECX, and EAX in sequence.
BSWAP swap the byte order in 32-bit registers
XCHG exchange word or byte. (at least one operand is a register, segment register cannot be used as the operand)
CMPXCHG compares and exchanges operands. (The second operand must be the accumulators AL/AX/EAX)
XADD switches and then accumulates (the result is in the first operand)
XLAT byte lookup conversion.
-- BX points to the starting point of a 256-byte table. AL indicates the index value of the table (0-255, that is
([BX + AL]-> AL)
2. input and output port transfer command.
In I/O port input. (Syntax: IN accumulators, {port number │ DX })
Out I/O port output. (Syntax: OUT {port number │ DX}, accumulators)
The input and output ports are scheduled in the immediate mode, and the range is 0-255. The input and output ports are scheduled in the DX mode,
The value range is 0-65535.
3. Destination Address Transfer command.
Load LEA to a valid address.
Example: lea dx, string; Save the offset address to DX.
LDS transfers the target pointer and loads the pointer content into DS.
For example: lds si, string; Save the segment address: Offset address to DS: SI.
LES transfers the target pointer and loads the pointer content into ES.
For example, les di and string; Save the segment address: Offset address to ES: DI.
LFS transfers the target pointer and loads the pointer content into FS.
For example: lfs di, string; Save the segment address: Offset address to FS: DI.
LGS transfers the target pointer and loads the pointer content into GS.
For example: lgs di, string; Save the segment address: Offset address to GS: DI.
The LSS transfers the target pointer and loads the pointer content to the SS.
For example: lss di, string; Save the segment address: Offset address to SS: DI.
4. Mark transfer command.
Transmit the LAHF flag register and load the flag into AH.
Send the SAHF flag register and load the AH content into the flag register.
PUSHF marks the inbound stack.
POPF marks the exit of the stack.
PUSHD 32-bit flag into the stack.
POPD 32-bit marks the stack.

Ii. arithmetic operation commands
---------------------------------------
ADD addition.
Addition of ADC incoming bits.
INC plus 1.
ASCII code adjustment for AAA addition.
Decimal adjustment of DAA addition.
SUB subtraction.
SBB with borrow subtraction.
DEC minus 1.
NEC reverse (minus 0) ...... the remaining full text>

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.