Learn 8086 assembly by running it
The 8086 is where the PC began, and its instruction set is still at the heart of every x86 processor. This guide covers all of it: every instruction, how the addressing modes and the flags work, and the DOS, BIOS and mouse services a program calls through INT.
Nothing here is just written down. Every one of the 198 examples was assembled with MASM and run on a real DOS, and you can play it back one instruction at a time: the line about to run, the registers and flags, the memory the program reads and writes, what it prints. Press ▷ on any example and watch the machine work.
When you want to write your own, sign in for a DOS machine in the cloud with MASM, Turbo C and QuickBASIC, an editor, and a debugger that shows the CPU and memory as your program runs.
Instructions
The 8086 instruction set, grouped the way the Intel manuals group it, with the topics around it: registers, addressing, segments, the assembler's directives.
Data transfer
Arithmetic
- ADDadd
- ADCadd with carry
- SUBsubtract
- SBBsubtract with borrow
- INCadd one
- DECsubtract one
- NEGchange sign
- CMPcompare
- MULunsigned multiply
- IMULsigned multiply
- DIVunsigned divide
- IDIVsigned divide
- CBWbyte to word, signed
- CWDword to doubleword, signed
- AAAASCII adjust after add
- AASASCII adjust after subtract
- AAMASCII adjust after multiply
- AADASCII adjust before divide
- DAAdecimal adjust after add
- DASdecimal adjust after subtract
Logic and bits
Control flow
- JMPjump unconditionally
- JE / JZjump if equal (zero)
- JNE / JNZjump if not equal (not zero)
- JA / JNBEjump if above (unsigned)
- JAE / JNB / JNCjump if above or equal (unsigned)
- JB / JNAE / JCjump if below (unsigned)
- JBE / JNAjump if below or equal (unsigned)
- JG / JNLEjump if greater (signed)
- JGE / JNLjump if greater or equal (signed)
- JL / JNGEjump if less (signed)
- JLE / JNGjump if less or equal (signed)
- JOjump if overflow
- JNOjump if no overflow
- JSjump if sign (negative)
- JNSjump if not sign (zero or positive)
- JP / JPEjump if parity even
- JNP / JPOjump if parity odd
- JCXZjump if CX is zero
- LOOPcount down CX and jump
- LOOPE / LOOPZloop while equal
- LOOPNE / LOOPNZloop while not equal
- INTcall an interrupt handler
- INTOinterrupt on overflow
- IRETreturn from an interrupt
Stack and procedures
Strings
- MOVSB / MOVSWcopy a string element
- CMPSB / CMPSWcompare two string elements
- SCASB / SCASWsearch a string for AL / AX
- LODSB / LODSWload a string element
- STOSB / STOSWstore AL / AX into a string
- REPrepeat CX times
- REPE / REPZrepeat while equal
- REPNE / REPNZrepeat while not equal
- CLD / STDchoose the string direction
Processor control
Addresses and data
Interrupts
The services a DOS program calls: INT 21h for DOS, the video, keyboard, disk and timer BIOS, the mouse driver, and the hardware interrupts behind them.
DOS · console
DOS · files
- 21h 3Chcreate or truncate a file
- 21h 5Bhcreate a file that must not exist yet
- 21h 3Dhopen an existing file
- 21h 3Ehclose a handle
- 21h 3Fhread from a file or device
- 21h 40hwrite to a file or device
- 21h 42hmove the file pointer
- 21h 41hdelete a file
- 21h 56hrename or move a file
- 21h 43hget or set file attributes
- 21h 57hget or set a file's date and time
- 21h 45hduplicate a handle
- 21h 44hdevice control: file or device?
DOS · disks and directories
DOS · memory and programs
DOS · system
BIOS · video
- 10hthe video BIOS
- 10h 00hset the video mode
- 10h 0Fhget the video mode
- 10h 01hset the cursor shape
- 10h 02hset the cursor position
- 10h 03hget the cursor position and shape
- 10h 05hselect the active display page
- 10h 06h/07hscroll a window up or down; clear it
- 10h 08hread the character and attribute at the cursor
- 10h 09hwrite a character with an attribute
- 10h 0Ahwrite a character, keep the colours
- 10h 0Ehteletype output
- 10h 0Bhset the border, background or CGA palette
- 10h 0Chwrite a pixel
- 10h 0Dhread a pixel
- 10h 10hpalette registers and the DAC
- 10h 11hfonts: the character generator
- 10h 12halternate select: EGA and VGA information, settings
- 10h 13hwrite a string
- 10h 1Ahget or set the display combination code
BIOS · keyboard
Mouse driver
BIOS · time, disks, system
- 1Ahthe time-of-day BIOS
- 1Ah 00hread the tick count
- 1Ah 02hread the real-time clock time
- 1Ah 04hread the real-time clock date
- 13hthe disk BIOS
- 13h 00hreset the disk system
- 13h 02hread disk sectors
- 13h 03hwrite disk sectors
- 15hthe AT system services
- 15h 86hwait a number of microseconds
- 15h 88hsize of extended memory