×

Embedded Systems Tutorial

AVR Microcontroller

8051 Microcontroller

8085 Microprocessor

8086 Microprocessor

8255 Microprocessor

Embedded Systems Practice

Subtraction of Two 8-bit BCD Numbers | 8086

In this tutorial, we will learn how to subtract two 8-bit BCD numbers in 8086 Microprocessor? By Ayush Sharma Last updated : May 22, 2023

Problem Statement

Write a program in 8086 microprocessor to find out the Subtraction of two 8 bits BCD numbers, where numbers are stored from starting memory address 2000 : 500 and store the result into memory address 2000 : 600 and carry (borrow) at 2000 : 601.

Algorithm

  1. Load data from offset 500 to register AL (first number)
  2. Load data from offset 501 to register BL (second number)
  3. Subtract these two numbers (contents of register AL and register BL)
  4. Apply DAS instruction (decimal adjust)
  5. Store the result (content of register AL) to offset 600
  6. Set register AL to 00
  7. Add contents of register AL to itself with carry (borrow)
  8. Store the result (content of register AL) to offset 601
  9. Stop

8086 program to subtract two 8 bit BCD numbers

ADDRESSMNEMONICSCOMMENTS
400MOV AL, [500]AL ← [500]
404MOV BL, [501]BL ← [501]
408SUB AL, BLAL ← AL-BL
40ADASDECIMAL ADJUST AL
40BMOV [600], ALAL → [600]
40FMOV AL, 00AL ← 00
411ADC AL, ALAL ← AL+AL+cy(prev)
413MOV [601], ALAL → [601]
417HLTEND

Explanation

  1. MOV AL, [500] load data from offset 500 to register AL.
  2. MOV BL, [501] load data from offset 501 to register BL.
  3. SUB AL, BL subtract contents of registers AL AND BL.
  4. DAS decimal adjust AL.
  5. MOV [600], AL store data from register AL to offset 600.
  6. MOV AL, 00 set value of register AL to 00.
  7. ADC AL, AL add contents of register AL to AL with borrow.
  8. MOV [601], AL store data from register AL to offset 601.
  9. HLT End.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.