Home » Embedded Systems

Find sum of the digits of an 8 bits number using 8086 Microprocessor

Here, we are going to learn how to find sum of the digits of an 8 bits number using 8086 Microprocessor?
Submitted by Ayush Sharma, on October 26, 2018

Problem statement:

Write an assembly language program in 8086 microprocessor to find sum of digit of an 8 bits number using 8 bits operation.

Assume 8 bit number is stored at memory location 2050.

Assumptions: Addresses of input data and output data are 2050 and 2051 respectively.

Algorithm:

  1. Load contents of memory location 2050 in register AL
  2. Copy content of register AL to register AH
  3. Assign 0004 to CX Register Pair
  4. Do AND operation on content of AL with 0F and store result in AL
  5. Rotate the contents of AH by executing ROL instruction using CX
  6. Do AND operation on content of AH with 0F and store result in AH
  7. Add AL and AH content and store result in AL
  8. Store the content of AL in memory location 2051

Program:

Mnemonics Comments
MOV AL, [2050] AL←[2050]
MOV AH, AL AH←AL
MOV CX, 0004 CX ← 0004
AND AL, 0F AL ← AL & 0F
ROL AH, CX Rotate AH content left by 4 bits(value of CX)
AND AH, 0F AH ← AH & 0F
ADD AL, AH AL←AL+AH
MOV [2051], AL [2051]←AL
HLT Stop Execution

Explanation

  1. MOV AL, [2050]: loads contents of memory location 2050 in AL
  2. MOV AH, AL: copy content of register AL to register AH
  3. MOV CX, 0004: assign 0004 to CX register pair
  4. AND AL, 0F: does AND operation on content of AL with 0F and store result in AL
  5. ROL AH, CX: rotate the content of AH register left by 4 bits i.e. value of CX register pair
  6. AND AH, 0F: does AND operation on content of AH with 0F and store result in AH
  7. ADD AL, AH: add AL and AH content and store result in AL
  8. MOV [2051], AL: stores the content of AL in 2051 memory address
  9. HLT: stops executing the program





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







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 some rights reserved.