Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Embedded Systems

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:

  1. Load 0000H into CX register (for borrow)
  2. Load the data into AX(accumulator) from memory 3000
  3. Load the data into BX register from memory 3002
  4. Subtract BX with Accumulator AX
  5. Jump if no borrow
  6. Increment CX by 1
  7. Move data from AX(accumulator) to memory 3004
  8. Move data from CX register to memory 3006
  9. Stop

Program:

ADDRESSMNEMONICSOPERANDSCOMMENTS
2000MOVCX, 0000[CX] <- 0000
2003MOVAX, [3000][AX] <- [3000]
2007MOVBX, [3002][BX] <- [3002]
200BSUBAX, BX[AX] <- [AX] – [BX]
200DJNC2010Jump if no borrow
200FINCCX[CX] <- [CX] + 1
2010MOV[3004], AX[3004] <- [AX]
2014MOV[3006], CX[3006] <- [CX]
2018HLTStop

Explanation:

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





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.