Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Last active November 23, 2017 00:32
Show Gist options
  • Save bit-hack/9aee55cb07e453ddc2bfd6ab2bb2443d to your computer and use it in GitHub Desktop.
Save bit-hack/9aee55cb07e453ddc2bfd6ab2bb2443d to your computer and use it in GitHub Desktop.
80186 instruction description file
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# DATA TRANSFER
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ MOV, Move
/ Register to Register/Memory
% 2/12 + 4*w
$ 1000100w | mod reg r/m
/ Register/memory to register
% 2/9 + 4*w
$ 1000101w | mod reg r/m
/ Immediate to register/memory
% 12/13 + 4*w
$ 1100011w | mod 000 r/m | data | data (if w=1)
/ Immediate to register
% 3/4 + 4*w
$ 1011wRRR | data | data (if w=1)
/ Memory to accumulator
% 8 + 4*w
$ 1010000w | addr-low | addr-high
/ Accumulator to memory
% 9 + 4*w
$ 1010001w | addr-low | addr-high
/ Register/memory to segment register
% 2/9 2/13
$ 10001110 | mod 0 reg r/m
/ Segment register to register/memory
% 2/11 2/15
$ 10001100 | mod 0 reg r/m
@ PUSH, Push
/ Memory
" group 0xfe / 0xff
% 16 20
$ 11111111 | mod 110 r/m
/ Register
% 10 14
$ 01010RRR
/ Segment register
% 9 13
$ 000RR110
/ Immediate
% 10 14
$ 011010s0 | data | data (if s=0)
@ PUSHA, Push All
% 36 68
$ 01100000
@ POP, Pop
/ Memory
% 20 24
$ 10001111 | mod 000 r/m
/ Register
% 10 14
$ 01011RRR
/ Segment register
" (reg != 01)
% 8 12
$ 000RR111
@ POPA, Pop All
% 51 83
$ 01100001
@ XCHG, Exchange
/ Register/memory with register
% 4/17 + 4*w
$ 1000011w | mod reg r/m
/ Register with accumulator
% 3
$ 10010RRR
@ IN, Input from
/ Fixed port
% 10 + 4*w
$ 1110010w | port
/ Variable port
% 8 + 4*w
$ 1110110w
@ OUT, Output to
/ Fixed port
% 9 + 4*w
$ 1110011w | port
/ Variable port
% 7 + 4*w
$ 1110111w
@ XLAT, Translate byte to AL
% 11 15
$ 11010111
@ LEA, Load EA to register
% 6
$ 10001101 | mod reg r/m
@ LDS, Load pointer to DS
" (mod != 11)
% 18 26
$ 11000101 | mod reg r/m
@ LES, Load pointer to ES
" (mod != 11)
% 18 26
$ 11000100 | mod reg r/m
@ LAHF, Load AH with flags
% 2
$ 10011111
@ SAHF, Store AH into flags
% 3
$ 10011110
@ PUSHF, Push flags
% 9 13
$ 10011100
@ POPF, Pop flags
% 8 12
$ 10011101
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# PREFIX
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ SEGMENT, Segment Override
" XX Segment:
" 00 ES
" 01 CS
" 10 SS
" 11 DS
% 2
$ 001XX110
@ LOCK, Bus lock prefix
% 2 3
$ 11110000
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# ARITHMETIC
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ ADD, Add
/ Reg/memory with register to either
% 3/10 + 4*w
$ 000000dw | mod reg r/m
/ Immediate to register/memory
" group 0x80 / 0x81 / 0x82 / 0x83
% 4/16 + 4*w
$ 100000sw | mod 000 r/m | data | data (if sw=01)
/ Immediate to accumulator
% 3/4 + 4*w
$ 0000010w | data | data (if w=1)
@ ADC, Add with carry
/ Reg/memory with register to either
% 3/10 + 4*w
$ 000100dw | mod reg r/m
/ Immediate to register/memory
" group 0x80 / 0x81 / 0x82 / 0x83
% 4/16 + 4*w
$ 100000sw | mod 010 r/m | data | data (if sw=01)
/ Immediate to accumulator
% 3/4 + 4*w
$ 0001010w | data | data (if w=1)
@ INC, Increment
/ Register/memory
" group 0xfe / 0xff
% 3/15 + 4*w
$ 1111111w | mod 000 r/m
/ Register
% 3
$ 01000RRR
@ SUB, Subtract
/ Reg/memory and register to either
% 3/10 + 4*w
$ 001010dw | mod reg r/m
/ Immediate from register/memory
" group 0x80 / 0x81 / 0x82 / 0x83
% 4/16 + 4*w
$ 100000sw | mod 101 r/m | data | data (if sw=01)
/ Immediate from accumulator
% 3/4 + 4*w
$ 0010110w | data | data (if w=1)
@ SBB, Subtract with borrow
/ Reg/memory and register to either
% 3/10 + 4*w
$ 000110dw | mod reg r/m
/ Immediate from register/memory
" group 0x80 / 0x81 / 0x82 / 0x83
% 4/16 + 4*w
$ 100000sw | mod 011 r/m | data | data (if sw=01)
/ Immediate from accumulator
% 3/4 + 4*w
$ 0001110w | data | data (if w=1)
@ DEC, Decrement
/ Register/memory
" group 0xfe / 0xff
% 3/15 + 4*w
$ 1111111w | mod 001 r/m
/ Register
% 3
$ 01001RRR
@ CMP, Compare
/ Register/memory with register
% 3/10 + 4*w
$ 0011101w | mod reg r/m
/ Register with register/memory
% 3/10 + 4*w
$ 0011100w | mod reg r/m
/ Immediate with register/memory
" group 0x80 / 0x81 / 0x82 / 0x83
% 3/10 + 4*w
$ 100000sw | mod 111 r/m | data | data (if sw=01)
/ Immediate with accumulator
% 3/4 + 4*w
$ 0011110w | data | data (if w=1)
@ NEG, Change sign register/memory
% 3/10 + 4*w
$ 1111011w | mod 011 r/m
@ AAA, ASCII adjust for add
% 8
$ 00110111
@ DAA, Decimal adjust for add
% 4
$ 00100111
@ AAS, ASCII adjust for subtract
% 7
$ 00111111
@ DAS, Decimal adjust for subtract
% 4
$ 00101111
@ MUL, Multiply (unsigned)
% Register-Byte 26-28
% Register-Word 35-37
% Memory-Byte 32-34
% Memory-Word 41-43 + 4*w
$ 1111011w | mod 100 r/m
@ IMUL, Integer multiply (signed)
% Register-Byte 25-28
% Register-Word 34-37
% Memory-Byte 31-34
% Memory-Word 40-43 + 4*w
$ 1111011w | mod 101 r/m
@ IMUL, Integer Immediate multiply (signed)
% 22-25/29-32 (if s=1)
$ 011010s1 | mod reg r/m | data | data (if s=0)
@ DIV, Divide (unsigned)
% Register-Byte 29
% Register-Word 38
% Memory-Byte 35
% Memory-Word 44 + 4*w
$ 1111011w | mod 110 r/m
@ IDIV, Integer divide (signed)
% Register-Byte 44-52
% Register-Word 53-61
% Memory-Byte 50-58
% Memory-Word 59-67 + 4*w
$ 1111011w | mod 111 r/m
@ AAM, ASCII adjust for multiply
% 19
$ 11010100 | 00001010
@ AAD, ASCII adjust for divide
% 15
$ 11010101 | 00001010
@ CBW, Convert byte to word
% 2
$ 10011000
@ CWD, Convert word to double word
% 4
$ 10011001
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# LOGIC
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ Shift/Rotate Instructions
" TTT Instruction
" 000 ROL
" 001 ROR
" 010 RCL
" 011 RCR
" 100 SHL/SAL
" 101 SHR
" 111 SAR
/ Register/Memory by
% 2/15 + 4*w
$ 1101000w | mod TTT r/m
/ Register/Memory by CL
% 5+n/17+n + 4*w
$ 1101001w | mod TTT r/m
/ Register/Memory by Count
% 5+n/17+n + 4*w
$ 1100000w | mod TTT r/m | count
@ AND, And
/ Reg/memory and register to either
% 3/10 + 4*w
$ 001000dw | mod reg r/m
/ Immediate to register/memory
% 4/16 + 4*w
$ 1000000w | mod 1 0 0 r/m data data (if w=1)
/ Immediate to accumulator
% 3/4 + 4*w
$ 0010010w | data | data (if w=1)
@ TEST, And function to flags, no result
/ Register/memory and register
% 3/10 + 4*w
$ 1000010w | mod reg r/m
/ Immediate data and register/memory
% 4/10 + 4*w
$ 1111011w | mod 000 r/m | data | data (if w=1)
/ Immediate data and accumulator
% 3/4 + 4*w
$ 1010100w | data | data (if w=1)
@ OR, Or
/ Reg/memory and register to either
% 3/10 + 4*w
$ 000010dw | mod reg r/m
/ Immediate to register/memory
% 4/16 + 4*w
$ 1000000w | mod 001 r/m | data | data (if w=1)
/ Immediate to accumulator
% 3/4 + 4*w
$ 0000110w | data | data (if w=1)
@ XOR, Exclusive or
/ Reg/memory and register to either
% 3/10 + 4*w
$ 001100dw | mod reg r/m
/ Immediate to register/memory
% 4/16 + 4*w
$ 1000000w | mod 110 r/m | data | data (if w=1)
/ Immediate to accumulator
% 3/4 + 4*w
$ 0011010w | data | data (if w=1)
@ NOT, Invert register/memory
% 3/10 3/10*
$ 1111011w | mod 010 r/m
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# STRING MANIPULATION
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ MOVS, Move byte/word
% 14 + 4*w
$ 1010010w
@ CMPS, Compare byte/word
% 22 + 4*w
$ 1010011w
@ SCAS, Scan byte/word
% 15 + 4*w
$ 1010111w
@ LODS, Load byte/wd to AL/AX
% 12 + 4*w
$ 1010110w
@ STOS, Store byte/wd from AL/AX
% 10 + 4*w
$ 1010101w
@ INS, Input byte/wd from DX port
% 14 + 4*w
$ 0110110w
@ OUTS, Output byte/wd to DX port
% 14 + 4*w
$ 0110111w
@ MOVS, Move string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 8 + 8n
$ 11110010 | 1010010w
@ CMPS, Compare string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 5 + 22n
$ 1111001z | 1010011w
@ SCAS, Scan string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 5 + 15n
$ 1111001z | 1010111w
@ LODS, Load string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 6 + 11n
$ 11110010 | 1010110w
@ STOS, Store string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 6 + 9n
$ 11110010 | 1010101w
@ INS, Input string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 8 + 8n
$ 11110010 | 0110110w
@ OUTS, Output string
" group 0xf2
" Repeated by count in CX (REP/REPE/REPZ/REPNE/REPNZ)
% 8 + 8n
$ 11110010 | 0110111w
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# CONTROL TRANSFER
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ CALL, Call
/ Direct within segment
% 15 19
$ 11101000 | disp-low | disp-high
/ Register/memory indirect within segment
" group 0xfe / 0xff
% 13/19 17/27
$ 11111111 | mod 010 r/m
/ Direct intersegment
% 23 31
$ 10011010 | segment offset | segment selector
/ Indirect intersegment
" group 0xfe / 0xff
% 38 54
" (mod != 11)
$ 11111111 | mod 011 r/m
@ JMP, Unconditional jump
/ Short/long
% 14
$ 11101011 | disp-low
/ Direct within segment
% 14
$ 11101001 | disp-low | disp-high
/ Register/memory indirect within segment
" group 0xfe / 0xff
% 11/17 11/21
$ 11111111 | mod 100 r/m
/ Direct intersegment
% 14
$ 11101010 | segment offset | segment selector
/ Indirect intersegment
" group 0xfe / 0xff
% 26 34
" (mod != 11)
$ 11111111 | mod 101 r/m
@ RET, Return from CALL
/ Within segment
% 16 20
$ 11000011
/ Within seg adding immed to SP
% 18 22
$ 11000010 | data-low | data-high
/ Intersegment
% 22 30
$ 11001011
/ Intersegment adding immediate to SP
% 25 33
$ 11001010 | data-low | data-high
@ JE/JZ, Jump on equal/zero
% 4/13 JMP not
$ 01110100 | disp
@ JL/JNGE, Jump on less/not greater or equal
% 4/13 4/13 taken/JMP
$ 01111100 | disp
@ JLE/JNG, Jump on less or equal/not greater
% 4/13 taken
$ 01111110 | disp
@ JB/JNAE, Jump on below/not above or equal
% 4/13
$ 01110010 | disp
@ JBE/JNA, Jump on below or equal/not above
% 4/13
$ 01110110 | disp
@ JP/JPE, Jump on parity/parity even
% 4/13
$ 01111010 | disp
@ JO, Jump on overflow
% 4/13
$ 01110000 | disp
@ JS, Jump on sign
% 4/13
$ 01111000 | disp
@ JNE/JNZ, Jump on not equal/not zero
% 4/13
$ 01110101 | disp
@ JNL/JGE, Jump on not less/greater or equal
% 4/13
$ 01111101 | disp
@ JNLE/JG, Jump on not less or equal/greater
% 4/13
$ 01111111 | disp
@ JNB/JAE, Jump on not below/above or equal
% 4/13
$ 01110011 | disp
@ JNBE/JA, Jump on not below or equal/above
% 4/13
$ 01110111 | disp
@ JNP/JPO, Jump on not par/par odd
% 4/13
$ 01111011 | disp
@ JNO, Jump on not overflow
% 4/13
$ 01110001 | disp
@ JNS, Jump on not sign
% 4/13
$ 01111001 | disp
@ JCXZ, Jump on CX zero
% 5/15
$ 11100011 | disp
@ LOOP, Loop CX times
% 6/16 LOOP not
$ 11100010 | disp
@ LOOPZ/LOOPE, Loop while zero/equal
% 6/16 taken/LOOP
$ 11100001 | disp
@ LOOPNZ/LOOPNE, Loop while not zero/equal
% 6/16 taken
$ 11100000 | disp
@ ENTER, Enter Procedure
" L = 0 (19 cycles)
" L = 1 (25 cycles)
" L > 1 (22 + 16(n-1) cycles)
% 25
$ 11001000 | data-low | data-high | L
@ LEAVE, Leave Procedure
% 8
$ 11001001
@ INT, Interrupt
/ Type specified
% 47
$ 11001101 | type
@ INT3, Debug Break
% 45 if INT. taken
$ 11001100
@ INTO, Interrupt on overflow
% 48/4 if INT. not taken
$ 11001110
@ IRET, Interrupt return
% 28
$ 11001111
@ BOUND, Detect value out of range
% 33/35
$ 01100010 | mod reg r/m
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# PROCESSOR CONTROL
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ CLC, Clear carry
% 2
$ 11111000
@ CMC, Complement carry
% 2
$ 11110101
@ STC, Set carry
% 2
$ 11111001
@ CLD, Clear direction
% 2
$ 11111100
@ STD, Set direction
% 2
$ 11111101
@ CLI, Clear interrupt
% 2
$ 11111010
@ STI, Set interrupt
% 2
$ 11111011
@ HLT, Halt
% 2
$ 11110100
@ WAIT, Wait
% 6 if TEST, 0
$ 10011011
@ ESC, Processor Extension Escape
" (TTT LLL are opcode to processor extension)
% 6
$ 11011TTT | mod LLL r/m
@ NOP, No Operation
% 3
$ 10010000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment