RTUEE / EC / EEEYr 2022 · Sem 52022

Q2Microprocessor

Question

15 marks

Q.2. Draw and explain the architecture of 8051 Microcontroller. Give PSW of 8051 Microcontroller and describe each bit in PSW.

Answer

The 8051 architecture comprises the CPU (ALU, register array, PSW), on-chip ROM and RAM, four I/O ports, two timers, a serial port, and an interrupt system, all connected via internal buses; the 8-bit PSW register holds the CY, AC, F0, RS1/RS0, OV, and P flags, used for arithmetic status and register bank selection.

8051 Architecture: the 8051 microcontroller's internal architecture is built around an 8-bit CPU core containing the Arithmetic Logic Unit (ALU, performing addition, subtraction, and logical operations), the Accumulator (A) and B registers (the primary operand/result registers for ALU operations, with B additionally used specifically in MUL and DIV instructions), and four banks of general-purpose working registers R0-R7 (only one bank active at a time, selected via the PSW's RS1/RS0 bits). This CPU core is connected via an internal bus to: on-chip Program Memory (ROM/Flash, 4KB in the original 8051, expandable via external memory using the EA pin), on-chip Data Memory (128 bytes of internal RAM in the original 8051, organized into the lower 32 bytes as four register banks, the next 16 bytes as bit-addressable space, and the remainder as general-purpose scratchpad RAM), four bidirectional 8-bit I/O ports (P0-P3, providing 32 total I/O lines, with P0/P2 additionally serving as the external memory address/data bus and several P3 pins serving alternate special functions), two 16-bit Timer/Counter units (Timer 0, Timer 1), a full-duplex UART serial port, and an interrupt control system managing the five interrupt sources through the IE and IP special function registers, with the entire chip's synchronous operation driven by an on-chip oscillator circuit working with an external crystal connected via the XTAL1/XTAL2 pins.

Program Status Word (PSW): the PSW is an 8-bit, bit-addressable special function register recording the outcome of the most recent arithmetic/logic operation and selecting the currently active register bank. Its bit layout (bit 7 to bit 0) is: CY (bit 7, Carry flag) — set if the last operation produced a carry-out/borrow-in at bit 7, also usable as a 1-bit Boolean accumulator for bit-manipulation instructions; AC (bit 6, Auxiliary Carry flag) — set if a carry occurred from bit 3 into bit 4, used to support BCD arithmetic correction via the DA A instruction; F0 (bit 5, user flag 0) — a general-purpose flag freely available for the programmer's own use, not automatically affected by hardware; RS1, RS0 (bits 4, 3, Register bank select) — jointly select which of the 4 register banks (0-3) is currently active for R0-R7 references; OV (bit 2, Overflow flag) — set if a signed arithmetic operation's result overflowed the valid signed 8-bit range, computed as the XOR of the carry-out of bit 6 and bit 7; (bit 1, reserved) — not used for any defined hardware purpose; P (bit 0, Parity flag) — automatically set to reflect the parity (odd/even count of 1-bits) of the current accumulator content after every instruction affecting A.

PSW Register Bit Layout (bit7 → bit0)CYACF0RS1RS0OV-Pbit7bit0

Significance of the register bank architecture: the 8051's four selectable register banks (each occupying 8 consecutive bytes of internal RAM: Bank 0 at 00H-07H, Bank 1 at 08H-0FH, Bank 2 at 10H-17H, Bank 3 at 18H-1FH) provide a distinctive fast context-switching capability not found in many contemporary 8-bit microcontrollers. Because switching the active bank is accomplished simply by changing the two RS1/RS0 bits in the PSW (a single-instruction operation, e.g., using SETB/CLR or a direct MOV to the PSW), an interrupt service routine can switch to an entirely different, private set of eight working registers (R0-R7) at its very start, perform all its internal processing using this private register set without disturbing the main program's register values in the previously active bank, and then switch back to the original bank before returning — entirely avoiding the need to individually PUSH each register the ISR intends to use onto the stack at entry and POP them back at exit, which would otherwise be the standard technique required on processors lacking this multiple-bank feature. This bank-switching approach is not only faster (fewer instructions, hence lower interrupt latency and overhead) but also simpler and less error-prone to implement correctly than manual stack-based register preservation.

Practical use of individual PSW flags: the CY flag is by far the most frequently tested flag in typical 8051 assembly programs, since conditional jump instructions JC (jump if carry set) and JNC (jump if carry clear) directly branch based on its state following an arithmetic operation, making it central to implementing multi-byte addition/subtraction (propagating the carry/borrow from one byte to the next in a multi-precision arithmetic routine) and general magnitude comparisons. The AC flag is used almost exclusively in conjunction with the DA A (Decimal Adjust Accumulator) instruction immediately following a BCD addition, correcting the accumulator's value so that it represents a valid BCD digit pair rather than a raw binary sum, which is essential whenever 8051 programs need to perform arithmetic directly on BCD-encoded data (such as adding two BCD digits displayed on a seven-segment display) without first converting to and from pure binary. The OV flag is specifically relevant only when the programmer is treating the accumulator's contents as a signed (two's complement) number — for unsigned arithmetic, the CY flag alone correctly indicates arithmetic overflow/underflow, but for signed arithmetic, only the OV flag correctly detects a result that has overflowed the valid signed range (-128 to +127), since a signed overflow can occur even when CY itself remains unset, and vice versa.

Relationship between the 8051's architecture and its instruction set design: the tight integration of the CPU core, on-chip memory, I/O ports, timers, and serial port within a single chip (rather than requiring these to be assembled from separate external ICs, as with a general-purpose microprocessor-based system) is precisely what allows the 8051's instruction set to include efficient, dedicated instructions for directly manipulating I/O port pins (SETB P1.0), reading/writing on-chip peripheral registers by name (MOV TH0, #data), and performing single-cycle bit tests (JB ACC.7, LABEL) — all of which would require considerably more instructions and external hardware-specific addressing logic on a comparable general-purpose microprocessor lacking this degree of on-chip integration, illustrating how the 8051's architecture and its instruction set were co-designed specifically to support efficient, compact embedded control programming.

Why the 8051 retains only 128 bytes of internal RAM: the original 8051's relatively small on-chip data memory (128 bytes) reflects the typical, modest data-storage requirements of the simple embedded control applications it was originally designed for (reading a handful of sensor inputs, maintaining a few counters/flags, driving simple actuator outputs) at the time of its introduction, rather than the much larger working-memory needs of general-purpose computing applications; later-generation 8051-compatible derivatives (such as the 8052, with 256 bytes of internal RAM, and many modern enhanced 8051-core variants with considerably more) extended this on-chip RAM capacity as embedded applications grew more sophisticated, while still preserving full backward software compatibility with the original 8051's instruction set and architecture, illustrating a common pattern in embedded microcontroller family evolution where a proven core architecture is incrementally extended with additional on-chip resources rather than being replaced outright.

Back to Paper