80386ASM programming foundation (3)

zhaozj2021-02-16  41

The assembly instructions and usage of 80386 will be described in the next four articles, and the instructions of 8086 are compared. The 80386 instruction set contains 8086/8088, 80186, 80286 instruction sets, which can be divided into several large categories: data transfer instructions, arithmetic operation / logical operation instructions, shift instructions, control transfer instructions, string operation instructions, advanced languages Supported instructions, conditional byte settings instructions, bit operation instructions, processor control instructions, and protection mode instructions. The advanced language support instruction begins with 80186, the protection mode instruction begins with 80286, and the conditional byte setting command and bit operation command are added 80386. This article mainly introduces data transfer commands, data transfer instructions can be divided into: universal data transfer, accumulator dedicated transmission, address transmission, flag transfer, respectively, as follows: A. Value Transfer Directive MOV, Movzx, Movsx, Xchg, Push, Pusha , Pushad, PoPA, POPAD, A.MOV, Directive, and 8086 are similar, but it supports 32-bit operations. B.MOVZX, zero extended transmission, format - Movzx DST, SRC, indicating that the part of the source operation is given, and the part of the target operabia is fill it. C.Movsx, Symbol Extended Transfer, Format --Movsx DST, SRC, indicates that the source sent to the destination operand, and the part of the purpose of the target is filld by the SRC symbol bit to give a simple example to demonstrate: MOV DL, 90H; MovsX AX, DL; AX = FF90H MOVZX AX, DL; AX = 0090H MOVSX ESI, DL; ESI = ffffff90h MOVZX ESI, DL; ESI = 00000090H In fact, there are two instructions CBW in 8086, CWD can be The operand is expanded. Movsx can extend the number of symbols, and Movzx can extend the unsigned number. Take a look at the CBW, CWD usage: CBW transfers the byte data extension, the symbol bit is extended to the AH CWD to extend the word data into double words. The symbol bit is placed in the DX MOV Al, 70H; CBW; // ax = 0070 cwd; // DX = 0000, AX = 0070 D.XCHG, the function and 8080 are the same, but it supports 8-bit, 16-bit, 32-bit operations The following statements are legal. XCHG AH, Al Xchg AX, Al Xchg ESI, EDI XCHG ESI, [EBX EDI 1000H] E.PUSH, and 8086 Different, it supports immediate number of stacks, 8-bit stack, of course there are 32-bit Stack, the following statements are legal. Push Al Push Bh Push 100H Push EAX PUSH EBX PUSH DWORD PTR [EAX] F.POP, function and usage are the same as 8086. G.Pusha, all of the 8 universal registers are all inrest, and the inrests are in stacks: AX, CX, DX, BX, SP, BP, SI, DI, and then the SP pointer storage is reduced by 16, but the SP is in the stack of PUSHA instructions. Pre-execution content. H.POPA, 8 universal registers all out of the stack, the stack pointer register is not popped in the stack, but adds 16, although the value though is the same as the content among the stack, but the physical significance is different. .

I.Pushad, all of the 8 32-bit general registers are all incorporated, and the contents of EAX, ECX, ECX, ECX, ECX, ECX, ECX, ECX, EBP, ESI, EDI, and ESP are the content J.POPAD before the execution of PUSHAD, 8 32 Pin Register All out of the stack, ESP's content see H B. Address Transfer Directive LEA, LDS, LES, LFS, LGS, LSS A.LEA, Take Effective Address, Function, Usage The same is the same as 8086, but it supports 32-bit operations . Rule: The purpose of the purpose must be a 16-bit or 32-bit universal register. When the number of operands are 16 bits, only the low 16 bits of the valid address are loaded. In fact, the Lea instruction is equivalent to the false command offset, see example: MOV EAX, 12345678H MOV EBX, 56784321H LEA ECX, [EAX EBX]; ECX = 99999999h B.LDS, load pointer, function, usage is the same as 8086, but it Support 32-bit operations. Format: LDS REG, OPRD. Rules, the destination register must be a 16-bit or 32-bit general register, and the OPRD must be a memory unit, and it is not an immediate number. If the destination register is 16 bits, then the source operand has a 32-bit pointer; if the destination register is 32 bits, then the source operand has a 48-bit pointer. This instruction sends four or six consecutive contents of the memory operated by the target operand OPRD to the DS segment register and instruction specified in the muse order command. For example: LDS EAX, [1000h]; this indicates that the contents of the offset address is 1000, 1001h, to the segment register DS, and will offset the address 1002, 1003, 1004, 1005 four byte units. The content is sent to EAX. LDS AX, [1000h]; this indicates that the content delivery segment register DS of the two byte units of 1000, 1001h, and transmits the contents of the offset addresses 1002, 1003h two byte units to Eax. C. Goes, with LDS, not per segment register is ES. D.LFS, with LDS, not the segment register is FS. E.lgs, with LDS, not in the segment register is GS. H.LSS, with LDS, not the segment register is SS. C. Sign Transfer Instruction LAHF, SAHF, PUSHF, PUSHFD, POPF, POPFD A.LAHF, send low 8 bits of the flag register to AH, including SF, ZF, ZF, PF, and CF.

B.SAHF, with the process of I just opposite C.PUSHF, turn the EFLAGS low of the flag register to the stack, and 8086 same D.Pushfd, put the contents of the flag register EFLAGS into the stack E.POPF, put one of the top of the stack The word pop, and send it to the low 16-bit F.POPFD of the flag register EFLAGS, pop the two words on the top and send it to the flag register EFLAGS D. Accumulator Transfer Instruction IN, OUT, Xlat A.in The same is the same as 8086, but you can enter a double byte, and if the range of ports is at 00h-FFH, it can be used directly. If this range is exceeded, the port number is sent to DX, and the following statement is legal: in Al, 20h; read a byte in Ax, 20h from the 20h port; read a word MOV DX, 0378H in Eax, DX from the 20h port; read two bytes B.out, and 8086, but You can output a double byte, and if the range of ports is located at 00h-FFH, it can be used directly. If this range is exceeded, the port number is sent to DX, and the following statement is legal: OUT 20H, Al; from 20h Port outputs a byte in 20h, AX; outputs a word MOV DX, 0378H in Eax, DX from the 20H port; outputs two words C.XLAT, check the table instruction, function and usage from the 20H port, but the base address The register uses EBX to see the implementation of the XLAT: XLAT uses BX as a base register, and the specified buffer checks the table with Al as an index register, and send the content of the Al specified location to Al, for example Say we write a small program in MS-DOS: C: /> Debug -a100 MOV BX, 0120 Sub Al, Al Mov DL, Al Mov AH, 2 INT 21 MOV AH, 4C INT 21 INT 20-E120 'Abcdefghijkllmmddkdk' = G100 screen will display a, if Al = 3, then the screen will display all of the above instructions do not affect the flag of EFLAGS.

转载请注明原文地址:https://www.9cbs.com/read-27091.html

New Post(0)