8051 assembly: a quick start with DOS/51

The 8051 is an 8-bit processor family that works with bytes and individual bits. Assembly lets you tell it exactly what to move, add or test. You can try it immediately in the free DOS/51 browser emulator—no programmer or physical board needed.

The Philips P80C31SFPN DIP-40 microcontroller sold by iMania
The ROMless 80C31: a classic 8051-family CPU with external program memory.

Learn the essentials first

  • A is the accumulator: the main register for arithmetic and data transfers.
  • MOV copies a value, destination first. MOV A,#42 loads the number 42; MOV A,0x30 reads the byte at internal address 0x30. The # matters.
  • MOVX accesses external data memory, while MOVC reads program memory. Identical numerical addresses need not refer to the same physical storage.
  • JZ/JNZ test A itself. There is no separate zero flag. Carry is used by instructions such as ADDC and SUBB.

Your first program: print an asterisk

Open DOS/51, type nano first.asm and enter this program. Save with Ctrl-O, leave with Ctrl-X, then type asm -r first.asm.

clr 0x99         ; TI = 0
mov a,#42        ; ASCII '*'
mov 0x99,a       ; SBUF
wait_tx:
    jnb 0x99,wait_tx
clr 0x99
ret

It prints * and returns to the shell. Byte address 0x99 is the UART transmit buffer SBUF; bit address 0x99 is TI, the transmission-complete flag. The instruction selects the address space. DOS/51 has already configured the UART, so this example does not change the console speed.

From the emulator to the real 80C31

The Philips P80C31SFPN in DIP-40 is ROMless: it needs external program memory, a clock, reset and address-latch circuitry. The emulator’s external RAM and SD card are board features, not memory or native SPI hidden inside the CPU. For physical construction, see our complete 80C31 breadboard-system guide.

Ready for the complete reference?

The Ultimate 8051 Assembly Guide covers all 44 standard mnemonics, 111 operand forms and 255 defined opcode bytes, with addressing, flags, stack, examples and peripherals. It distinguishes classic CPU behavior, Philips-specific documentation and features actually modeled by the emulator.

Prefer a retro field manual? New emulator SD cards include the ASCII edition. On an existing card, click Install field manual; existing files are preserved. Read the index with sdget guide51.txt, then cat guide51.txt. Chapters are split to fit the small RAM disk.

Read the Ultimate 8051 Assembly Guide →