# 8086 program to subtract two 16 bit BCD numbers

• Last Updated : 31 May, 2018

Prerequisite – 8086 program to subtract two 8 bit BCD numbers
Problem – Write a program in 8086 microprocessor to find out the subtraction of two 16-bit BCD numbers, where numbers are stored from starting offset 500 and store the result into offset 600.

Example –

Algorithm –

1. Load data from offset 500 to register AL
2. Load data from offset 502 to register BL
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. Load data from offset 501 to register AL
7. Load data from offset 503 to register BL
8. Subtract these two numbers with borrow.(contents of register AL and register BL)
9. Apply DAS instruction (decimal adjust)
10. Store the result (content of register AL) to offset 601
11. Set register AL to 00
12. Add contents of register AL to itself with carry
13. Store the result (content of register AL) to offset 602
14. Stop

Program –

400MOV AL, [500]AL<-[500]
404MOV BL, [502]BL<-[502]
408SUB AL, BLAL<-AL-BL
40BMOV [600], ALAL->[600]
40FMOV AL, [501]AL<-[501]
413MOV BL, [503]BL<-[503[
417SBB AL, BLAL<-AL-BL-borrow
41AMOV [601], ALAL->[601]
41EMOV AL, 00AL<-00
422MOV [602], ALA->[602]
426HLTEnd

Explanation –

1. MOV AL, [500]: load data from offset 500 to register AL
2. MOV BL, [502]: load data from offset 502 to register BL
3. SUB AL, BL: subtract contents of registers AL AND BL
4. DAS: decimal adjust
5. MOV [600], AL: store data from register AL to offset 600
6. MOV AL, [501]: load data from offset 501 to register AL
7. MOV BL, [503]: load data from offset 503 to register BL
8. SBB AL, BL: subtract contents of registers AL AND BL with borrow
9. DAS: decimal adjust
10. MOV [601], AL: store data from register AL to offset 601
11. MOV AL, 00: set value of register AL to 00
12. ADC AL, AL: add contents of register AL to AL with carry
13. MOV [601], AL: store data from register AL to offset 601
14. HLT: end
My Personal Notes arrow_drop_up