Lobsters retrocomputing - 27 Nov 2026

Page 2 of 3

| | 366 xPm Op Eb |

| | 367 xPm Op Ew |

| | SHIFTS & ROTATIONS |

| | ------------------ |

| | Comments: |

| | * Where applicable, N is masked off by 0x1f. |

| | * For Rxx and Sxx, OF is predictably affected only when N is 1. |

| | * SHLD and SHRD affect all 6 arithmetic flags, but OF and AF unpredictably. |

| | * RxL: OF = (CF != high order bit of L) before shift |

| | * RxR: OF = (high order bit of L != next high order bit of L) before shift |

| | * SxL: OF = (CF != sign bit of L) after shift |

| | * SxR: OF = (sign bit of L) after shift |

| | P Op Description |

| | 0 ROL CF <- [<-<-<-] <- high order bit Rotate |

| | 1 ROR low order bit -> [->->->] -> CF |

| | 2 RCL CF <- [<-<-<-] <- CF Rotate Through CF |

| | 3 RCR CF -> [->->->] -> CF |

| | 4 SHL CF <- [<-<-<-] <- 0 Shift (unsigned) |

| | 5 SHR 0 -> [->->->] -> CF |

| | 4 SAL CF <- [<-<-<-] <- 0 Shift (signed) |

| | 7 SAR sign bit -> [->->->] -> CF |

| | * 300 xPm Db Op Eb, Db |

| | * 301 xPm Db Op Ew, Db |

| | 320 xPm Op Eb, 1 |

| | 321 xPm Op Ew, 1 |

| | 322 xPm Op Eb, CL |

| | 323 xPm Op Ew, CL |

| | SHLD L, E, N CF:L = L:E << N |

| | SHRD L, E, N L:CF = E:L >> N |

| | # 017 244 Db shld Ew, Rw, Db |

| | # 017 245 shld Ew, Rw, CL |

| | # 017 254 Db shrd Ew, Rw, Db |

| | # 017 255 shrd Ew, Rw, CL |

| | TYPE CONVERSIONS |

| | ---------------- |

| | [] Decimal Conversions |

| | Comments: |

| | * DAA and DAS are used for adjusting the results of addition and subtraction |

| | respectively back to packed BCD format. They will alter all 6 of the |

| | arithmetic flags, OF unpredictably. |

| | * AAA, AAS, AAD, and AAM are used for adjusting the results of the four |

| | basic arithmetic operations back to unpacked BCD format or ASCII format. |

| | However, AAD is used *before* a divide operation. They too affect all |

| | 6 of the arithmetic flags, but only AF and CF predictably (for AAA and |

| | AAS) or SF, ZF and PF (for AAD and AAM). |

| | * In the following, A0 stands for the lower 4 bits of AL and A1 the upper |

| | 4 bits of AL. |

| | * The binary codes for AAM and AAD each consist of an opcode followed by |

| | a constant 10 (012 in octal). It has been said that this "10" is |

| | actually a hidden parameter to a more general AAD and AAM operator, |

| | which can actually be used for any base other than 10. Some processors |

| | will not allow AAD to be generalized in this way, however. The reason it |

| | was left out in the open like this was supposedly because the original |

| | 8086 design literally ran out of space to pack in the opcode. |

| | DAA if (A0 > 9) AF = 1; if (AF) AL += (0x10 - 10); |

| | if (A1 > 9) CF = 1; if (CF) AL += (0x10 - 10)*0x10; |

| | DAS if (A0 > 9) AF = 1; if (AF) AL -= (0x10 - 10); |

| | if (A1 > 9) CF = 1; if (CF) AL += (0x10 - 10)*0x10; |

| | AAA if (A0 > 9) AF = 1; CF = AF; if (CF) A0 += (0x10 - 10), AH++; |

| | AAS if (A0 > 9) AF = 1; CF = AF; if (CF) A0 -= (0x10 - 10), AH--; |

| | AAM AX = AL/10 : AL%10 |

| | AAD AX = (10*AH + AL)%0x10 |

| | 047 daa |

| | 057 das |

| | 067 aaa |

| | 077 aas |

| | 324 012 aam |

| | 325 012 aad |

| | [] Sign Conversions |

| | Comments: |

| | * In converting from a shorter to longer operand size, sign conversion |

| | involves either taking the leading (sign) bit and replicating it leftward |

| | (conversion to signed), or placing zero's on the left (for conversion |

| | to unsigned). |

| | MOVSX L, E L = (signed)E |

| | MOVZX L, E L = (unsigned)E |

| | # 017 266 xrm movsx Rw, Eb |

| | # 017 267 xrm movsx Rw, Ew |

| | # 017 266 xrm movzx Ew, Rb |

| | # 017 277 xrm movzx Ew, Rw |

| | CBW AX = (signed)AL |

| | CWDE EAX = (signed)AX |

| | CWD DX:AX = (signed)AX |

| | CDQ EDX:EAX = (signed)EAX |

| | 230 cbw / (#) cwde |

| | 231 cwd / (#) cdq |

| | [] Byte Ordering |

| | * Used to convert between "little Endian" (Intel byte ordering) and "big |

| | Endian" (Motorola byte ordering). Typical use: networking applications. |

| | BSWAP L L[0]:L[1]:L[2]:L[3] = L[3]:L[2]:L[1]:L[0] |

| | @ 017 31r bswap Rd |

| | [] Table Lookup |

| | XLATB AL = [BX + AL] |

| | 327 xlatb |

| | SEMAPHORES & SYNCHRONIZATION |

| | ---------------------------- |

| | Comments: |

| | * All these operations affect all 6 arithmetic flags. BT, BTS, BTR, BTC |

| | affect only CF predictably; and BSF and BSR affect only ZF predictably. |

| | * ACC is either AL, AX or EAX in CMPXCHG, depending on the operand size. |

| | * WAIT is used in the '486 to force a pending unmasked interrupt from the |

| | internal floating point processing unit. |

| | * LOCK is a prefix used in multi-CPU contexts to assure exclusive access to |

| | memory for the following two-step read & modify operations: |

| | (INC, DEC, NEG, NOT) Mem (ADD, ADC, SUB, SBB) Mem, Src |

| | (BT, BTS, BTR, BTC) Mem, Src (AND, XOR, OR) Mem, Src |

| | XCHG Reg, Mem XCHG Mem, Reg |

| | But XCHG automatically does its own LOCK so does not need to be prefixed. |

| | P Op Description |

| | 4 BT L, N CF = L.N; |

| | 5 BTS L, N CF = L.N; L.N = 1; |

| | 6 BTR L, N CF = L.N; L.N = 0; |

| | 7 BTC L, N CF = L.N; L.N = !L.N; |

| | # 017 2P3 xrm Op Ew, Rw |

| | # 017 272 xPm Db Op Ew, Db |

| | BSF L, E ZF = !E; if (ZF) L = First 1-bit position in E; else L = ??? |

| | BSR L, E ZF = !E; if (ZF) L = Last 1-bit position in E; else L = ??? |

| | # 017 274 xrm bsf Rw, Ew |

| | # 017 275 xrm bsr Rw, Ew |

| | CMPXCHG L, E ZF = (ACC == L); if (ZF) L = E; else ACC = L; |

| | @ 017 246 xrm cmpxchg Eb, Rb |

| | @ 017 247 xrm cmpxchg Ew, Rw |

| | XADD L, L' <L, L'> = <L + L', L> |

| | @ 017 300 xrm xadd Eb, Rb |

| | @ 017 301 xrm xadd Ew, Rw |

| | NOP Delay 1 cycle. |

| | WAIT Wait for coprocessor unit. |

| | LOCK Hardware memory bus semaphore. |

| | HLT Wait for a reset or interrupt. |

| | 220 nop |

| | 233 wait |

| | 360 lock |

| | 364 hlt |

| | INT N push [E]FLAGS, CS, [E]IP; TF = 0; |

| | if (the Nth entry in the IDT is a Interrupt Gate) IF = 0; |

| | jmp to the far address listed under the Nth entry in the IDT |

| | INTO if (OF) INT 4 |

| | IRET if (NT) return to task listed under TSS.BackLink; |

| | else pop [E]IP, CS, [E]FLAGS; |

| | 314 int 3 |

| | 315 Db int Db |

| | 316 into |

| | 317 iret |

| | FLAGS |

| | ----- |

| | Comments: |

| | * No flags are affected except the explicit moves to the FLAGS register: |

| | POPF[D] and SAHF, but SAHF only sets the arithmetic flags (except OF). |

| | POPF pop FLAGS |

| | POPFD pop EFLAGS |

| | PUSHF push FLAGS |

| | PUSHFD push EFLAGS |

| | SAHF FLAGS \|= (AH & 0xd5) |

| | LAHF AH = FLAGS; |

| | 234 pushf / (#) pushfd |

| | 235 popf / (#) popfd |

| | 236 sahf |

| | 237 lahf |

| | CMC CF = !CF |

| | CLC CF = 0 |

| | STC CF = 1 |

| | CLI IF = 0 (Interrupts off) |

| | STI IF = 1 (Interrupts on) |

| | CLD DF = 0 (Set string ops to increment) |

| | STD DF = 1 (Set string ops to decrement) |

| | 365 cmc |

| | 370 clc |

| | 371 stc |

| | 372 cli |

| | 373 sti |

| | 374 cld |

| | 375 std |

| | CONDITIONAL OPERATIONS |

| | ---------------------- |

| | (NOTE: The values listed for CC are in octal). |

| | CC Condition(s) Definition Descriptions |

| | 07 A NBE !CF && !ZF x > y x > 0 (unsigned) |

| | 03 AE NB !CF x >= y x >= 0 (unsigned) |

| | 02 B NAE CF x < y x < 0 (unsigned) |

| | 06 BE NA CF \|\| ZF x <= y x <= 0 (unsigned) |

| | 17 G NLE SF == OF && !ZF x > y x > 0 (signed) |

| | 15 GE NL SF == OF x >= y x >= 0 (signed) |

| | 14 L NGE SF != OF x < y x < 0 (signed) |

| | 16 LE NG SF != OF \|\| ZF x <= y x <= 0 (signed) |

| | 04 E Z ZF x == y x == 0 |

| | 05 NE NZ !ZF x != y x != 0 |

| | 00 O OF Overflow (signed overflow) |

| | 01 NO !OF No overflow (signed overflow) |

| | 02 C CF Carry (unsigned overflow) |

| | 03 NC !CF No carry (unsigned overflow) |

| | 10 S SF (Negative) sign |

| | 11 NS !SF No (negative) sign |

| | 12 P PE PF Parity [even] |

| | 13 NP PO !PF No parity (parity odd) |

| | CC cc Cond. |

| | Jcc Rel if (Cond) EIP += Rel; |

| | SETcc L L = (Cond)? 1: 0; |

| | # 017 200+CC Cw jcc Cw '=&h80+cc |

| | # 017 220+CC x0m setcc Rb '=&h90+cc |

| | 160+CC jcc Cb '=&h70+cc |

| | STACK OPERATIONS |

| | ---------------- |

| | Comments: |

| | * PUSHA[D] uses the value SP had before the operation started. |

| | * POPA[D] doesn't actually affect [E]SP, which is why it's bracketed out. |

| | * POP CS is not allowed because it's already subsumed by the RET (far) |

| | operation. Instead, 017 is used as a 2-byte operation prefix. |

| | * POP SS inhibits interrupts in order to allow [E]SP to be altered in the |

| | following operation -- for what should be obvious reasons. |

| | PUSH E SP -= sizeof E; SS:[SP] = E; |

| | PUSHA push AX, CX, DX, BX, SP, BP, SI, DI |

| | PUSHAD push EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI |

| | # 017 240 push FS |

| | # 017 250 push GS |

| | 0s6 push SR (s = 0-3) |

| | 12r push Rw |

| | * 140 pusha / (#) pushad |

| | 150 Dw push Dw |

| | 152 Dc push Dc |

| | 377 x6m push Ew |

| | POP L L = SS:[SP]; SP += sizeof L; |

| | POPA pop DI, SI, BP, (SP), BX, DX, CX, AX |

| | POPAD pop EDI, ESI, EBP, (ESP), EBX, EDX, ECX, EAX |

| | # 017 241 pop FS |

| | # 017 251 pop GS |

| | 0s7 pop SR (s = 0, 2-3) |

| | 13r pop Rw |

| | * 141 popa / (#) popad |

| | 217 x0m pop Ew |

| | TRANSFER OPERATIONS |

| | ------------------- |

| | Comments: |

| | * XCHG can have its operands listed in either order. |

| | * MOV CS, ... is not allowed, since this is already subsumed by JMPs. |

| | * LCS ... is not allowed either for the same reason. |

| | * XCHG AX, AX is one and the same as NOP. |

| | XCHG L, E <L, E> = <E, L> |

| | 206 xrm xchg Rb, Eb |

| | 207 xrm xchg Rw, Ew |

| | 22r xchg AX, Rw (r != 0) |

| | MOV L, E L = E; |

| | 210 xrm mov Eb, Rb |

| | 211 xrm mov Ew, Rw |

| | 212 xrm mov Rb, Eb |

| | 213 xrm mov Rw, Ew |

| | 214 xsm mov Es, SR (s = 0-3, (#) 4-5) |

| | 216 xsm mov SR, Es (s = 0,2-3, (#) 4-5) |

| | 240 Dw mov AL, [Dw] |

| | 241 Dw mov AX, [Dw] |

| | 242 Dw mov [Dw], AL |

| | 243 Dw mov [Dw], AX |

| | 26r Db mov Rb, Db |

| | 27r Dw mov Rw, Dw |

| | 306 x0m Db mov Eb, Db |

| | 307 x0m Dw mov Ew, Dw |

| | LEA L, An L = &An; |

| | 215 xrm lea Rw, En (x != 3) |

| | LSeg L, Af Seg:L = &Af; |

| | # 017 262 xrm lss Rw, Ef (x != 3) |

| | # 017 264 xrm lfs Rw, Ef (x != 3) |

| | # 017 265 xrm lgs Rw, Ef (x != 3) |

| | 304 xrm les Rw, Ef (x != 3) |

| | 305 xrm lds Rw, Ef (x != 3) |

| | ADDRESSING |

| | ---------- |

| | Comments: |

| | * The current mode of the machine determines its default mode (16 or 32 |

| | bits). |

| | * RAND: and ADDR: (not an standard name, since Intel has none) are |

| | prefixes that alter the default for the next instruction only. |

| | * RAND: changes the word size between 16 and 32 bits. |

| | * ADDR: changes the address size between 16 and 32 bits. |

| | * seg: cannot override the implied ES:[DI] operand in any string op, |

| | but can override the DS in the implied DS:[SI] operands there. |

| | seg: Segment override prefix |

| | ADDR: Address size toggle |

| | RAND: Operand size toggle |

| | 305 xrm lds Rw, Ef (x != 3) |

| | 046 ES: |

| | 056 CS: |

| | 066 SS: |

| | 076 DS: |

| | # 144 FS: |

| | # 145 GS: |

| | # 146 RAND: |

| | # 147 ADDR: |

| | PORT I/O |

| | -------- |

| | Comments: |

| | * In protected mode the user of these operations must pass the I/O |

| | Privilege Level (IOPL) else they are blocked by an interrupt. |

| | This allows the Operating System to spool I/O devices in a |

| | multitasking system (since the OS handles interrupts) to avoid having |

| | processes all trying to use the same device at once. |

| | IN ACC, Port ACC = IO[Port] |

| | 344 Db in AL, Db |

| | 345 Db in AX, Db |

| | 354 in AL, DX |

| | 355 in AX, DX |

| | OUT Port, ACC IO[Port] = ACC |

| | 346 Db out Db, AL |

| | 347 Db out Db, AX |

| | 356 out DX, AL |

| | 357 out DX, AX |

| | STRING OPERATIONS |

| | ----------------- |

| | Comments: |

| | * In all these operations below, Src denotes DS;[ESI] and Dest ES:[EDI]. |

| | * Dest cannot be overridden by a segment prefix, only Src. |

| | * The pointes (ESI, EDI) are bumped up (DF = 0) or down (DF = 1) after |

| | the operation by sizeof Operand. |

| | * ACC is either AL, AX or EAX depending on the operand size. |

| | * The flags altered are exactly those altered by the corresponding |

| | MOV, IN, OUT, or CMP operation (namely: only SCAS and CMPS alter the |

| | flags and in the same way as CMP) and these are therefore the only ones |

| | that can be prefixed by REP[N]E/REP[N]Z. |

| | * REP with all string ops, but REP LODS doesn't do anything sensible. |

| | INS in Dest, DX |

| | OUTS out DX, Src |

| | MOVS mov Dest, Src |

| | CMPS cmp Dest, Src |

| | STOS mov Dest, ACC |

| | LODS mov ACC, Src |

| | SCAS cmp ACC, Dest |

| | * 154 insb |

| | * 155 insw / (#) insd |

| | * 156 outsb |

| | * 157 outsw / (#) outsd |

| | 244 movsb |

| | 245 movsw / (#) movsd |

| | 246 cmpsb |

| | 247 cmpsw / (#) cmpsd |

| | 252 stosb |

| | 253 stosw / (#) stosd |

| | 254 lodsb |

| | 255 lodsw / (#) lodsd |

| | 256 scasb |

| | 257 scasw / (#) scasd |

| | REP Op while (CX-- > 0) Op |

| | REPE /REPZ Op while (CX-- > 0 && ZF) Op |

| | REPNE/REPNZ Op while (CX-- > 0 && !ZF) Op |

| | 362 repne / repnz / rep |

| | 363 repe / repz |

| | CONTROL FLOW |

| | ------------ |

| | Comments: |

| | * The distinction between near and far jumps/calls/returns is built right |

| | into the 8086 language, which pretty much forces you to explicitly |

| | declare a routine as "near" or "far" and be consistent about it. The |

| | intended usage runs pretty much like C's static vs. global functions, |

| | with each C file being analogous to an 8086 segment. |

| | * The 8086 was specifically designed to be a Pascal (and PL/I) machine, |

| | though. Intel wrongly assumed that one of these languages would become |

| | like C is now. So the ENTER and LEAVE operators were added (and BOUND |

| | to do array bounds-checking). The segmentation structure was intended |

| | to support these types of languages. |

| | JCXZ Rel if (!CX) IP += Rel; |

| | JECXZ Rel if (!ECX) IP += Rel; |

| | LOOPcc Rel if (!--CX && cc) IP += Rel; |

| | 340 Cb loopnz Cb / loopne Cb |

| | 341 Cb loopz Cb / loope Cb |

| | 342 Cb loop Cb |

| | 343 Cb jcxz Cb / (#) jecxz Cb |

| | JMP Rel IP += Rel; |

| | JMP FAR Af CS:IP = Af; |

| | CALL Rel push IP; IP += Rel; |

| | CALL FAR Af push CS, IP; IP = Af; |

| | 232 Af call Af |

| | 350 Cw call Cw |

| | 351 Cw jmp Cw |

| | 352 Af jmp far Af |

| | 353 Cb jmp Cb |

| | 377 x2m call En |

| | 377 x3m call far Ef |

| | 377 x4m jmp En |

| | 377 x5m jmp far Ef |

| | RET Params pop IP; SP += Params (default: Params = 0) |

| | RET FAR Params pop IP, CS; SP += Params (default: Params = 0) |

| | 302 Dw ret Dw |

| | 303 ret |

| | 312 Dw ret far Dw |

| | 313 ret far |

| | ENTER Locs, N push EBP; |

| | (sub EBP, 4; push [EBP]) N-1 times, if N > 0 |

| | mov EBP, ESP |

| | (add EBP, 4*(N-1); push EBP), if N > 0 |

| | sub ESP, Locs |

| | LEAVE mov ESP, EBP; pop EBP |

| | * 310 Dw Db enter Dw, Db |

| | * 311 leave |

| | SYSTEM CONTROL & MEMORY PROTECTION |

| | ---------------------------------- |

| | BOUND A, AA if (A not in range AA[0]..AA[1]) INT 5 |

| | ARPL L, E ZF = (L.RPL < E.RPL); |

| | if (ZF) L.RPL = E.RPL; |

| | * 142 xrm bound Rw, Ed |

| | $ 143 xrm arpl Es, Rw |

| | SLDT Sel Sel = LDTR |

| | STR Sel Sel = TR |

| | LLDT Sel LDTR = Sel |

| | LTR Sel TR = Sel |

| | VERR Sel ZF = (Sel is accessible and has read-access) |

| | VERW Sel ZF = (Sel is accessible and has write-access) |

| | LAR L, Sel ZF = (Sel is accessible); |

| | if (ZF) L = the access rights of Sel's descriptor. |

| | LSL L, Sel ZF = (Sel is accessible); |

| | if (ZF) L = the segment limit of Sel's descriptor. |

| | $ 017 000 x0m sldt Ew |

| | $ 017 000 x1m str Ew |

| | $ 017 000 x2m lldt Ew |

| | $ 017 000 x3m ltr Ew |

| | $ 017 000 x4m verr Ew |

| | $ 017 000 x5m verw Ew |

| | $ 017 002 xrm lar Rw, Ew |

| | $ 017 003 xrm lsl Rw, Ew |

| | SGDT Desc Desc = GDTR |

| | SIDT Desc Desc = IDTR |

| | LGDT Desc GDTR = Desc |

| | LIDT Desc IDTR = Desc |

| | $ 017 001 x0m sgdt Ep |

| | $ 017 001 x1m sidt Ep |

| | $ 017 001 x2m lgdt Ep |

| | $ 017 001 x3m lidt Ep |

| | SMSW L L = MSW ... note that MSW is CR0 bits 0-15. |

| | LMSW E MSW = E |

| | CLTS MSW.3 = 0 ... clears the Task Switched flag. |

| | $ 017 001 x4m smsw Ew |

| | $ 017 001 x6m lmsw Ew |

| | $ 017 006 clts |

| | INVD Invalidate internal cache. |

| | WBINVD Invalidate internal cache, after writing it back. |

| | INVLPD Ea Invalidate Ea's page. |

| | @ 017 010 invd |

| | @ 017 011 wbinvd |

| | @ 017 020 x7m invlpg Ea |

| | MOV Reg, SysReg |

| | MOV SysReg, Reg |

Next page | Previous page | More Lobsters retrocomputing | Headlines

Original: https://gist.github.com/seanjensengrey/f971c20d05d4d0efc0781f2f3c0353da