Monday, September 21, 2026

8 bit data addition | 8085 Lab Program

 Section: Arithmetic & Logic Operations

Aim: To add two 8-bit numbers stored at consecutive memory locations and also to verify the result.

Apparatus Required: 8085 microprocessor kit, keyboard.

Algorithm:

  1. Initialize memory pointer to data location.
  2. Get the first number from memory into accumulator.
  3. Get the second number and add it to the accumulator.
  4. Store the answer at another memory location.

Program:

AddressLabelMnemonicsOperandComment
4100STARTMVIC, 00Clear C reg.
4102LXIH, 4200Initialize HL reg. to 4200
4105MOVA, MTransfer first data to accumulator
4106INXHIncrement HL reg. to point next memory location
4107ADDMAdd first number to acc. content
4108JNCL1Jump to location if result does not yield carry
410BINRCIncrement C reg.
410CL1INXHIncrement HL reg. to point next memory location
410DMOVM, ATransfer the result from acc. to memory
410EINXHIncrement HL reg. to point next memory location
410FMOVM, CMove carry to memory
4110HLTStop the program

Observation:

  • Input:
    • Memory location 4200: 40
    • Memory location 4201: 20
  • Output:
    • Memory location 4202: 60 (Sum)
    • Memory location 4203: 00 (Carry)

Result: Thus the two 8-bit numbers stored at 4200 & 4201 are added and the result is stored at 4202 & 4203.

Flow Chart: 

  +-------------------+

               |       START       |

               +---------+---------+

                         |

                         v

               +-------------------+

               |    [C] <- 00H     |

               +---------+---------+

                         |

                         v

               +-------------------+

               |   [HL] <- 4200H   |

               +---------+---------+

                         |

                         v

               +-------------------+

               |    [A] <- [M]     |

               +---------+---------+

                         |

                         v

               +-------------------+

               |  [HL] <- [HL] + 1 |

               +---------+---------+

                         |

                         v

               +-------------------+

               |  [A] <- [A] + [M] |

               +---------+---------+

                         |

                         v

                       /   \

                     /  Is   \

                   /  there a  \

                  <   Carry?   >

                   \          /

                     \      /

                       \  /

                        |

            +-----------+-----------+

            |                       |

           YES                      NO

            |                       |

            v                       |

  +-------------------+             |

  |   [C] <- [C] + 1  |             |

  +---------+---------+             |

            |                       |

            +-----------+-----------+

                        |

                        v

              +-------------------+

              |  [HL] <- [HL] + 1 |

              +---------+---------+

                        |

                        v

              +-------------------+

              |    [M] <- [A]     |

              +---------+---------+

                        |

                        v

              +-------------------+

              |  [HL] <- [HL] + 1 |

              +---------+---------+

                        |

                        v

              +-------------------+

              |    [M] <- [C]     |

              +---------+---------+

                        |

                        v

              +-------------------+

              |       STOP        |

              +-------------------+ 

Viva Questions:

  1. What is the function of LXI H, 4000 H instruction?
  2. How can you store data in a memory location?
  3. What is the meaning of INX?
  4. How can you read data from a memory location?
  5. What are the flags available in 8085?
  6. What is the function of the RESET key of an 8085 microprocessor kit?
  7. What is the function of JNC instruction?
  8. What is the difference between conditional and unconditional jump instructions?
  9. What is multibyte addition/subtraction?


For all 2026 published articles list: click here

…till the next post, bye-bye & take care

Sunday, September 20, 2026

Interrupts in 8051 Microcontroller | 8051 Microcontroller

In embedded systems programming, real-time responsiveness is critical. A microcontroller must be capable of responding immediately to high-priority events, such as a sensor input or a timer overflow, without wasting valuable CPU cycles on constant polling. The Intel 8051 microcontroller solves this through a robust, hardware-driven interrupt system.

An interrupt is essentially an event that temporarily diverts the processor from its current execution path. Analogous to receiving an important phone call while performing a task, the microcontroller pauses its main work, services the immediate request, and then seamlessly returns to where it left off.


The 8051 Interrupt Execution Process

8051-interrupt-structure-process

When an interrupt is triggered, the 8051 does not halt instantly. Instead, it transitions gracefully through a sequence of hardware-defined steps:

  1. Instruction Completion: The processor completes the execution of the instruction currently in progress.
  2. State Saving: The current contents of the Program Status Word (PSW) are pushed onto the stack to preserve status flags.
  3. Address Preservation: The Program Counter (PC) content (the return address of the next instruction in the main program) is pushed onto the stack.
  4. Flag Reset: The internal interrupt flag is automatically reset.
  5. ISR Branching: The PC is loaded with the predefined starting address of the Interrupt Service Routine (ISR), forcing the program to jump to the service program.

Every ISR must conclude with the RETI (Return from Interrupt) instruction. When RETI executes, it signals the completion of the routine and performs the reverse operations:

  1. Pops the stack top back to the Program Counter (PC).
  2. Pops the next stack top back to the Program Status Word (PSW), successfully restoring the main program's exact execution state.

Taxonomy of Interrupts

Interrupts can be classified under three major conceptual pairings:

  • External vs. Internal: External interrupts are initiated by physical peripheral devices connected to the microcontroller's pins. The 8051 has two external hardware interrupts, INT0 and INT1, which trigger based on a level or edge signal applied to pins Port 3.2 and Port 3.3. Internal interrupts are triggered by on-chip peripherals, such as timers or serial communication controllers.
  • Maskable vs. Non-Maskable: Maskable interrupts can be dynamically enabled or disabled by software commands. Non-maskable interrupts are high-priority hardware lines that the programmer cannot disable through code.
  • Vectored vs. Non-Vectored: In vectored interrupts, the microcontroller automatically jumps to a predefined, hardcoded ISR address (the "vector address"). Non-vectored interrupts rely on an external handshaking process: the microcontroller acknowledges the interrupt with an INTA signal, and the peripheral device must send the target vector address back across the data bus.

All five of the standard 8051 interrupts are classified as maskable and vectored.


The 8051 Interrupt Vector Table

The starting address of the ISR is called the interrupt vector. The 8051 family features five primary interrupts (plus the system RESET line, which acts as the ultimate master interrupt). They are serviced according to a strict priority hierarchy:

Interrupt SourceTrigger FlagTypeVector AddressNatural Priority
RESETInternal/External0000HHighest Priority
External Interrupt 0 (INT0)IE0 / PORT3.2External0003HSecond Highest (Highest of the 5 MCUs)
Timer 0 Overflow (TF0)TF0Internal000BHThird Highest
External Interrupt 1 (INT1)IE1 / PORT3.3External0013HFourth Highest
Timer 1 Overflow (TF1)TF1Internal001BHFifth Highest
Serial Communication (RI/TI)RI / TIInternal0023HLowest Priority

Control and Priority Registers

To configure and manipulate these interrupts, developers utilize three specialized Special Function Registers (SFRs):

1. IE Register (Interrupt Enable)

8051-Interrupt-Enable-Register

This 8-bit register allows developers to activate or silence individual interrupts. Setting a bit to 1 enables that interrupt, while 0 disables it.

  • Bit 7 (EA - Enable All): The global switch. If EA = 0, all interrupts are disabled regardless of individual settings. If EA = 1, individual interrupt settings are respected.
  • Bit 4 (ES): Serial interrupt enable.
  • Bit 3 (ET1): Timer 1 interrupt enable.
  • Bit 2 (EX1): External 1 interrupt enable.
  • Bit 1 (ET0): Timer 0 interrupt enable.
  • Bit 0 (EX0): External 0 interrupt enable.

2. IP Register (Interrupt Priority)

8051-Interrupt-Priority-Register

The 8051 allows developers to customize the natural priority hierarchy using the IP register. Setting a bit to 1 assigns high priority to that specific interrupt, while 0 assigns low priority:

  • Bit 4 (PS): High priority for serial interrupt.
  • Bit 3 (PT1): High priority for Timer 1 interrupt.
  • Bit 2 (PX1): High priority for External 1 interrupt.
  • Bit 1 (PT0): High priority for Timer 0 interrupt.
  • Bit 0 (PX0): High priority for External 0 interrupt.

Rules of Priority Resolution:

  • A low-priority interrupt can only be interrupted by a high-priority interrupt, never by another low-priority request.
  • If different priority level interrupts arrive simultaneously, the higher level is served.
  • If identical priority level interrupts are requested at the exact same time, an internal, hardware-level polling sequence determines which interrupt gets serviced first.

3. TCON Register (Timer Control)

8051-TCON-register

The TCON register serves a dual purpose. It is primarily used to start, stop, and monitor timer overflows. However, it also contains specialized bits that specify the triggering type—either edge-activated or level-activated—for the external interrupt pins.


Conclusion

The interrupt structure of the Intel 8051 is a masterclass in deterministic hardware control. By combining a fixed vector table, prioritized execution rules, and highly configurable SFRs like IE and IP, it guarantees that critical system operations are handled with zero-latency efficiency—cementing its place as a cornerstone of embedded education and design.



For all 2026 published articles list: click here

…till the next post, bye-bye & take care