# Subtract Two 16-bits numbers | 8086 Microprocessor

Here, we are going to learn how to **find the subtraction of two 16-bits numbers using 8086 Microprocessor**?

Submitted by Ayush Sharma, on November 08, 2018

**Problem:** Write a program to subtract two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address.

**Algorithm:**

- Load 0000H into CX register (for borrow)
- Load the data into AX(accumulator) from memory 3000
- Load the data into BX register from memory 3002
- Subtract BX with Accumulator AX
- Jump if no borrow
- Increment CX by 1
- Move data from AX(accumulator) to memory 3004
- Move data from CX register to memory 3006
- Stop

**Program:**

ADDRESS | MNEMONICS | OPERANDS | COMMENTS |
---|---|---|---|

2000 | MOV | CX, 0000 | [CX] <- 0000 |

2003 | MOV | AX, [3000] | [AX] <- [3000] |

2007 | MOV | BX, [3002] | [BX] <- [3002] |

200B | SUB | AX, BX | [AX] <- [AX] – [BX] |

200D | JNC | 2010 | Jump if no borrow |

200F | INC | CX | [CX] <- [CX] + 1 |

2010 | MOV | [3004], AX | [3004] <- [AX] |

2014 | MOV | [3006], CX | [3006] <- [CX] |

2018 | HLT | Stop |

**Explanation:**

**MOV**is used to load and store data.**SUB**is used to subtract two numbers where their one number is in accumulator or not.**JNC**is a 2-bit command which is used to check whether the borrow is generated from accumulator or not.**INC**is used to increment an register by 1.**HLT**is used to stop the program.**AX**is an accumulator which is used to load and store the data.**BX, CX**is general purpose registers where BX is used for storing second number and CX is used to store borrow.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.