Tuesday, September 22, 2026

8 bit data subtraction | 8085 Lab Program

 Section: Arithmetic & Logic Operations

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

Apparatus Required: 8085 microprocessor kit, key board.

Algorithm:

  1. Initialize memory pointer to data location.
  2. Get the first number from memory in accumulator.
  3. Get the second number and subtract from the accumulator.
  4. If the result yields a borrow, the content of the acc. is complemented and 01H is added to it (2’s complement). A register is cleared and the content of that reg. is incremented in case there is a borrow. If there is no borrow the content of the acc. is directly taken as the result.
  5. Store the answer at next memory location.

Program:

AddressLabelMnemonicsOperandComment
4100STARTMVIC, 00Clear C reg.
4102LXIH, 4200Initialize HL reg. to 4500
4105MOVA, MTransfer first data to accumulator
4106INXHIncrement HL reg. to point next mem. Location.
4107SUBMSubtract first number from acc. Content.
4108JNCL1Jump to location if result does not yield borrow.
410BINRCIncrement C reg.
410CCMAComplement the Acc. Content
410DADI01HAdd 01H to content of acc.
410FL1INXHIncrement HL reg. to point next mem. Location.
4110MOVM, ATransfer the result from acc. to memory.
4111INXHIncrement HL reg. to point next mem. Location.
4112MOVM, CMove carry to mem.
4113HLTStop the program

Observation:

  • Input:
    • Address 4200: 04
    • Address 4201: 01
  • Output:
    • Address 4202: 03
    • Address 4203: 00

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

Flowchart:

               +-------------------+
               |       START       |
               +---------+---------+
                         |
                         v
               +-------------------+
               |    [C] <- 00H     |
               +---------+---------+
                         |
                         v
               +-------------------+
               |   [HL] <- 4200H   |
               +---------+---------+
                         |
                         v
               +-------------------+
               |    [A] <- [M]     |
               +---------+---------+
                         |
                         v
               +-------------------+
               |  [HL] <- [HL] + 1 |
               +---------+---------+
                         |
                         v
               +-------------------+
               |  [A] <- [A] - [M] |
               +---------+---------+
                         |
                         v
                       /   \
                     /  Is   \
                   /  there a  \
                  <   Borrow?  >
                   \          /
                     \      /
                       \  /
                        |
            +-----------+-----------+
            |                       |
           YES                      NO
            |                       |
            v                       |
  +-------------------+             |
  |  Complement [A]   |             |
  |  Add 01H to [A]   |             |
  +---------+---------+             |
            |                       |
            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 meant by ADI instruction?
  2. What is an instruction?
  3. What is Mnemonic?
  4. What is the purpose of CMA instruction?
  5. What is the function of stack pointer?
  6. Why ADI 01H is used in two’s complement of an 8-bit number?
  7. How many memory locations can be addressed by a microprocessor with 14 address lines?


For all 2026 published articles list: click here

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