Memory spaces
| Space | Addresses | Reached by |
|---|---|---|
| Code (program memory) | 0x0000-0xFFFF (16 bits) | instruction fetch, MOVC, the jumps and calls |
| Internal data RAM | 0x00-0x7F (direct), 0x00-0xFF (indirect, through @R0 and @R1) | dir operands below 0x80, @Ri |
| Special function registers (SFR) | 0x80-0xFF | dir operands from 0x80 |
| External data (XDATA) | 16-bit through DPTR, 8-bit through @Ri | MOVX only |
The register bank R0 to R7 is eight bytes of the internal RAM: the instruction table of the Ghidra 8051 definition places the four banks at 0x00-0x07, 0x08-0x0F, 0x10-0x17 and 0x18-0x1F, selected by the
RS1 and RS0 bits (PSW bits 4 and 3) of the program status word. The stack lives in the internal RAM.
Bit addressing
A bit address is one byte. Bit addresses 0x00-0x7F are the 128 bits of the internal RAM bytes 0x20-0x2F: bit address b is bit b & 7 of byte 0x20 + (b >> 3). Bit addresses 0x80-0xFF are the bits of
the special function registers whose address is a multiple of eight: bit address b is bit b & 7 of the register at b & 0xF8. The disassembly shows the first kind as 0x21.3 and the second as ACC.7 when the register is a standard one.
Registers
| Register | Width | Use |
|---|---|---|
A (ACC, SFR 0xE0) | 8 | accumulator: the operand and result of most arithmetic and logic |
B (SFR 0xF0) | 8 | the second operand of MUL AB and DIV AB |
DPTR (DPH 0x83, DPL 0x82) | 16 | data pointer: MOVX, MOVC, JMP @A+DPTR, INC DPTR, MOV DPTR,#d16 |
SP (SFR 0x81) | 8 | stack pointer, used by PUSH, POP, calls and returns |
PSW (SFR 0xD0) | 8 | program status word: carry CY (bit 7), auxiliary carry AC (bit 6), register bank select RS1 and RS0 (bits 4 and 3), overflow OV (bit 2) |
The standard SFR names the disassembly knows (the addresses of Ghidra’s 8051.pspec and the MCS-51 family): P0 0x80, SP 0x81, DPL 0x82, DPH 0x83, PCON 0x87, TCON 0x88, TMOD 0x89, TL0 0x8A, TL1 0x8B, TH0 0x8C, TH1 0x8D, P1 0x90, SCON 0x98, SBUF 0x99, P2 0xA0, IE 0xA8, P3 0xB0, IP 0xB8, T2CON 0xC8, RCAP2L 0xCA, RCAP2H 0xCB, TL2 0xCC, TH2 0xCD, PSW 0xD0, ACC 0xE0, B 0xF0.
Flags
The carry CY, auxiliary carry AC and overflow OV are changed by the instructions marked on the instructions page: ADD, ADDC and SUBB change all three;
MUL and DIV change CY and OV; CJNE, DA, the rotates through the carry and the carry bit instructions change CY. The other PSW bits are not described on this site yet.
Not described
Known, not yet covered
- Reference: the PSW bits other than
CY,AC,RS1,RS0andOV(the user flags and the parity flag), the SFR bit names (TR0,EA...), the interrupt vectors and priorities, and the registers of the Cypress FX2.