Transcription of H:Appsdevelemu8086documentation8086 …
1 Complete 8086 instruction set Quick reference: Operand types: REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP. SREG: DS, ES, SS, and only as second operand: CS. memory: [BX], [BX+SI+7], variable, (see Memory Access). immediate: 5, -24, 3Fh, 10001101b, Notes: zWhen two operands are required for an instruction they are separated by comma. For example: REG, memory zWhen there are two operands, both operands must have the same size (except shift and rotate instructions ). For example: AL, DL DX, AX m1 DB ? AL, m1 m2 DW ? AX, m2 zSome instructions allow several operand combinations. For example: memory, immediate AAA AAD AAM AAS ADC ADD AND CALL CBW CLC CLD CLI CMC CMP CMPSB CMPSW CWD DAA DAS DEC DIV HLT IDIV IMUL IN INC INT INTO IRET JA JAE JB JBE JC JCXZ JE JG JGE JL JLE JMP JNA JNAE JNB JNBE JNC JNE JNG JNGE JNL JNLE JNO JNP JNS JNZ JO JP JPE JPO JS JZ LAHF LDS LEA LES LODSB LODSW LOOP LOOPE LOOPNE LOOPNZ LOOPZ MOV MOVSB MOVSW MUL NEG NOP NOT OR OUT POP POPA POPF PUSH PUSHA PUSHF RCL RCR REP REPE REPNE REPNZ REPZ RET RETF ROL ROR SAHF SAL SAR SBB SCASB SCASW SHL SHR STC STD STI STOSB STOSW SUB TEST XCHG XLATB XOR Page 1 of 538086 instructionsREG, immediate memory, REG REG, SREG zSome examples contain macros, so it is advisable to use Shift + F8 hot key to Step Over (to make macro code execute at maximum speed set step delay to zero)
2 , otherwise emulator will step through each instruction of a macro. Here is an example that uses PRINTN macro: include ' ' ORG 100h MOV AL, 1 MOV BL, 2 PRINTN 'Hello World!' ; macro. MOV CL, 3 PRINTN 'Welcome!' ; macro. RET These marks are used to show the state of the flags: 1 - instruction sets this flag to 1. 0 - instruction sets this flag to 0. r - flag value depends on result of the instruction. ? - flag value is undefined (maybe 1 or 0). Some instructions generate exactly the same machine code, so disassembler may have a problem decoding to your original code. This is especially important for Conditional Jump instructions (see "Program Flow Control" in Tutorials for more information). instructions in alphabetical order: InstructionOperandsDescription ASCII Adjust after Addition. Corrects result in AH and AL after addition when working with BCD values.
3 It works according to the following Algorithm: if low nibble of AL > 9 or AF = 1 then: Page 2 of 538086 instructionsAAA No operandszAL = AL + 6 zAH = AH + 1 zAF = 1 zCF = 1 else zAF = 0 zCF = 0 in both cases: clear the high nibble of AL. Example:MOV AX, 15 ; AH = 00, AL = 0Fh AAA ; AH = 01, AL = 05 RET CZSOPAr????rAAD No operandsASCII Adjust before Division. Prepares two BCD values for division. Algorithm: zAL = (AH * 10) + AL zAH = 0 Example:MOV AX, 0105h ; AH = 01, AL = 05 AAD ; AH = 00, AL = 0Fh (15) RET CZSOPA?rr?r?ASCII Adjust after Multiplication. Corrects the result of multiplication of two BCD values. Algorithm: zAH = AL / 10 zAL = remainder Page 3 of 538086 instructionsAAM No operands Example:MOV AL, 15 ; AL = 0Fh AAM ; AH = 01, AL = 05 RET CZSOPA?rr?r?AAS No operandsASCII Adjust after Subtraction. Corrects result in AH and AL after subtraction when working with BCD values.
4 Algorithm: if low nibble of AL > 9 or AF = 1 then: zAL = AL - 6 zAH = AH - 1 zAF = 1 zCF = 1 else zAF = 0 zCF = 0 in both cases: clear the high nibble of AL. Example:MOV AX, 02 FFh ; AH = 02, AL = 0 FFh AAS ; AH = 01, AL = 09 RET CZSOPAr????rADC REG, memory memory, REG REG, REG Add with Carry. Algorithm: operand1 = operand1 + operand2 + CF Example:Page 4 of 538086 instructionsmemory, immediate REG, immediate STC ; set CF = 1 MOV AL, 5 ; AL = 5 ADC AL, 1 ; AL = 7 RET CZSOPA rrrrrrADD REG, memory memory, REG REG, REG memory, immediate REG, immediate Add. Algorithm: operand1 = operand1 + operand2 Example:MOV AL, 5 ; AL = 5 ADD AL, -3 ; AL = 2 RET CZSOPA rrrrrrAND REG, memory memory, REG REG, REG memory, immediate REG, immediate Logical AND between all bits of two operands. Result is stored in operand1. These rules apply: 1 AND 1 = 1 1 AND 0 = 0 0 AND 1 = 0 0 AND 0 = 0 Example:MOV AL, 'a' ; AL = 01100001b AND AL, 11011111b ; AL = 01000001b ('A') RET CZSOP0rr0rTransfers control to procedure, return address is (IP) is pushed to stack.
5 4-byte address may be entered in this form: 1234h:5678h, first value is a Page 5 of 538086 instructionsCALL procedure name label 4-byte address segment second value is an offset (this is a far call, so CS is also pushed to stack). Example: ORG 100h ; for COM file. CALL p1 ADD AX, 1 RET ; return to OS. p1 PROC ; procedure declaration. MOV AX, 1234h RET ; return to caller. p1 ENDP CZSOPA unchangedCBW No operandsConvert byte into word. Algorithm: if high bit of AL = 1 then: zAH = 255 (0 FFh) else zAH = 0 Example:MOV AX, 0 ; AH = 0, AL = 0 MOV AL, -5 ; AX = 000 FBh (251) CBW ; AX = 0 FFFBh (-5) RET CZSOPA unchangedClear Carry flag. Algorithm: CF = 0 Page 6 of 538086 instructionsCLC No operands C0 CLD No operandsClear Direction flag. SI and DI will be incremented by chain instructions : CMPSB, CMPSW, LODSB, LODSW, MOVSB, MOVSW, STOSB, STOSW. Algorithm: DF = 0 D0 CLI No operandsClear Interrupt enable flag.
6 This disables hardware interrupts. Algorithm: IF = 0 I0 CMC No operandsComplement Carry flag. Inverts value of CF. Algorithm: if CF = 1 then CF = 0 if CF = 0 then CF = 1 CrCompare. Algorithm: operand1 - operand2 Page 7 of 538086 instructionsCMP REG, memory memory, REG REG, REG memory, immediate REG, immediate result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to result. Example:MOV AL, 5 MOV BL, 5 CMP AL, BL ; AL = 5, ZF = 1 (so equal!) RET CZSOPA rrrrrrCMPSB No operandsCompare bytes: ES:[DI] from DS:[SI]. Algorithm: zDS:[SI] - ES:[DI] zset flags according to result: OF, SF, ZF, AF, PF, CF zif DF = 0 then {SI = SI + 1 {DI = DI + 1 else {SI = SI - 1 {DI = DI - 1 Example: open from c:\emu8086\examples CZSOPA rrrrrrCMPSW No operandsCompare words: ES:[DI] from DS:[SI]. Algorithm: zDS:[SI] - ES:[DI] zset flags according to result: OF, SF, ZF, AF, PF, CF zif DF = 0 then {SI = SI + 2 {DI = DI + 2 else {SI = SI - 2 {DI = DI - 2 Page 8 of 538086 instructionsexample: open from c:\emu8086\examples CZSOPA rrrrrrCWD No operandsConvert Word to Double word.}}}}}}}}
7 Algorithm: if high bit of AX = 1 then: zDX = 65535 (0 FFFFh) else zDX = 0 Example:MOV DX, 0 ; DX = 0 MOV AX, 0 ; AX = 0 MOV AX, -5 ; DX AX = 00000h:0 FFFBh CWD ; DX AX = 0 FFFFh:0 FFFBh RET CZSOPA unchangedDAA No operandsDecimal adjust After Addition. Corrects the result of addition of two packed BCD values. Algorithm: if low nibble of AL > 9 or AF = 1 then: zAL = AL + 6 zAF = 1 if AL > 9Fh or CF = 1 then: zAL = AL + 60h zCF = 1 Example:Page 9 of 538086 instructionsMOV AL, 0Fh ; AL = 0Fh (15) DAA ; AL = 15h RET CZSOPA rrrrrrDAS No operandsDecimal adjust After Subtraction. Corrects the result of subtraction of two packed BCD values. Algorithm: if low nibble of AL > 9 or AF = 1 then: zAL = AL - 6 zAF = 1 if AL > 9Fh or CF = 1 then: zAL = AL - 60h zCF = 1 Example:MOV AL, 0 FFh ; AL = 0 FFh (-1) DAS ; AL = 99h, CF = 1 RET CZSOPA rrrrrrDEC REG memory Decrement.
8 Algorithm: operand = operand - 1 Example:MOV AL, 255 ; AL = 0 FFh (255 or -1) DEC AL ; AL = 0 FEh (254 or -2) RET CF - unchanged! ZSOPA rrrrrPage 10 of 538086 instructionsDIV REG memory Unsigned divide. Algorithm: when operand is a byte: AL = AX / operand AH = remainder (modulus) when operand is a word: AX = (DX AX) / operand DX = remainder (modulus) Example:MOV AX, 203 ; AX = 00 CBh MOV BL, 4 DIV BL ; AL = 50 (32h), AH = 3 RET CZSOPA??????HLT No operandsHalt the System. Example:MOV AX, 5 HLT CZSOPA unchangedIDIV REG memory Signed divide. Algorithm: when operand is a byte: AL = AX / operand AH = remainder (modulus) when operand is a word: AX = (DX AX) / operand DX = remainder (modulus) Example:MOV AX, -203 ; AX = 0FF35h MOV BL, 4 IDIV BL ; AL = -50 (0 CEh), AH = -3 (0 FDh) RET Page 11 of 538086 instructions CZSOPA??????IMUL REG memory Signed multiply. Algorithm: when operand is a byte: AX = AL * operand.
9 When operand is a word: (DX AX) = AX * operand. Example:MOV AL, -2 MOV BL, -4 IMUL BL ; AX = 8 RET CF=OF=0 when result fits into operand of IMUL. CZSOPAr??r??IN AL, AL, DX AX, AX, DX Input from port into AL or AX. Second operand is a port number. If required to access port number over 255 - DX register should be used. Example:IN AX, 4 ; get status of traffic lights. IN AL, 7 ; get status of stepper-motor. CZSOPA unchangedINC REG memory Increment. Algorithm: operand = operand + 1 Example:MOV AL, 4 INC AL ; AL = 5 Page 12 of 538086 instructionsRET CF - unchanged! ZSOPA rrrrrINT immediate byte Interrupt numbered by immediate byte ( ). Algorithm: Push to stack: {flags register {CS {IP zIF = 0 zTransfer control to interrupt procedure Example:MOV AH, 0Eh ; teletype. MOV AL, 'A' INT 10h ; BIOS interrupt. RET CZSOPAI unchanged0 INTO No operandsInterrupt 4 if Overflow flag is 1.}}}
10 Algorithm: if OF = 1 then INT 4 Example:; -5 - 127 = -132 (not in ) ; the result of SUB is wrong (124), ; so OF = 1 is set: MOV AL, -5 SUB AL, 127 ; AL = 7Ch (124) INTO ; process error. RET Interrupt Return. Page 13 of 538086 instructionsIRET No operandsAlgorithm: Pop from stack: {IP {CS {flags register CZSOPA popped JA label Short Jump if first operand is Above second operand (as set by CMP instruction). Unsigned. Algorithm: if (CF = 0) and (ZF = 0) then jump Example: include ' ' ORG 100h MOV AL, 250 CMP AL, 5 JA label1 PRINT 'AL is not above 5' JMP exit label1: PRINT 'AL is above 5' exit: RET CZSOPA unchangedJAE label Short Jump if first operand is Above or Equal to second operand (as set by CMP instruction). Unsigned. Algorithm: if CF = 0 then jump Example: include ' ' ORG 100h MOV AL, 5 CMP AL, 5 JAE label1 PRINT 'AL is not above or equal to 5' JMP exit label1: Page 14 of 538086 instructions PRINT 'AL is above or equal to 5' exit: RET CZSOPA unchangedJB label Short Jump if first operand is Below second operand (as set by CMP instruction).}}}