8086 Summary of assembly instructions

Source: Internet
Author: User
Tags mul

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 Summary of assembly instructions

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.