All cheatsheets

Cheatsheets

8051 (MCS-51)

Registers, SFRs & ports, addressing modes, and common assembly instructions.

Visualize

8051 — bit-addressable port (P1)

SFRs like P1 are bit-addressable — flip one pin (SETB / CLR) without touching the others.

off
off
off
off
off
off
off
off
P1 = 0x00bin 0000 0000dec 0

Tap a pin to toggle it, or run an instruction. SETB / CLR change one bit; MOV writes the whole byte.

pin high · bit-addressable SFR — flip any pin without touching the others.

30 entries

Registers & memory7

A (ACC)

Accumulator — most arithmetic/logic uses it

B

Aux register (MUL / DIV)

R0–R7

General registers — 4 banks selected by PSW RS1:RS0.

DPTR

16-bit data pointer (external/code memory)

SP

Stack pointer (defaults to 0x07)

PSW

Program status word — CY, AC, RS1:RS0, OV, P

PC

Program counter (16-bit)

SFRs & ports6

P0–P3 (0x80/90/A0/B0)

8-bit bidirectional I/O ports

TMOD / TCON

Timer mode / control

TH0/TL0, TH1/TL1

Timer 0 / 1 high & low bytes

SCON / SBUF

Serial control / buffer (UART)

IE / IP

Interrupt enable / priority

PCON

Power control (idle, power-down, SMOD)

Addressing modes6

MOV A, #25h

Immediate

MOV A, 30h

Direct (internal RAM / SFR)

MOV A, R0

Register

MOV A, @R0

Indirect (R0/R1 point into RAM)

MOVC A, @A+DPTR

Code memory (look-up tables)

MOVX A, @DPTR

External data memory

Common instructions8

MOV / MOVX / MOVC

Move (internal / external / code)

ADD, ADDC, SUBB, INC, DEC

Arithmetic

MUL AB / DIV AB

Multiply / divide A and B

ANL, ORL, XRL, CPL, RL, RR

Logic & rotate

SETB / CLR bit

Set / clear a bit (e.g. SETB P1.0)

JNB / JB / JC / JNC

Bit & carry conditional jumps

CJNE / DJNZ

Compare-and-jump / decrement-and-jump

ACALL / LCALL / RET / RETI

Call / return — RETI (not RET) ends an interrupt.

Programs & routines3

Blink an LED on P1.0

Complete program: toggle a pin in a loop with a delay.

Timer 0 delay

Recipe: a precise delay with Timer 0 (mode 1, 16-bit).

ISR (interrupt routine)

Recipe: an external-interrupt service routine.