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

Find the largest among 8-bit N numbers | 8086 Microprocessor



Here, we are going to write an assembly language program in 8086 microprocessor to find the largest among 8-bit N numbers.
Submitted by Ayush Sharma, on November 08, 2018

Problem: Write a program in 8086 microprocessor to find out the largest among 8-bit n numbers, where size n is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501 and store the result (largest number) into memory address 2000 : 600.

Algorithm:

  1. Load data from offset 500 to register CL and set register CH to 00 (for count).
  2. Load first number (value) from next offset (i.e. 501) to register AL and decrease count by 1.
  3. Now compare value of register AL from data(value) at next offset, if that data is greater than value of register AL then update value of register AL to that data else no change, and increase offset value for next comparison and decrease count by 1 and continue this till count (value of register CX) becomes 0.
  4. Store the result (value of register AL) to memory address 2000 : 600.

Program:

ADDRESSMNEMONICSCOMMENTS
400MOV SI, 500SI ← 500
403MOV CL, [SI]CL ← [SI]
405MOV CH, 00CH ← 00
407INC SISI ← SI+1
408MOV AL, [SI]AL ← [SI]
40ADEC CLCL ← CL-1
40CINC SISI ← SI+1
40DCMP AL, [SI]AL-[SI]
40FJNC 413JUMP TO 413 IF CY=0
411MOV AL, [SI]AL ← [SI]
413INC SISI ← SI+1
414LOOP 40DCX ← CX-1 & JUMP TO 40D IF CX NOT 0
416MOV [600], ALAL → [600]
41AHLTEND

Explanation:

  1. MOV SI, 500: set the value of SI to 500
  2. MOV CL, [SI]: load data from offset SI to register CL
  3. MOV CH, 00: set value of register CH to 00
  4. INC SI: increase value of SI by 1
  5. MOV AL, [SI]: load value from offset SI to register AL
  6. DEC CL: decrease value of register CL by 1
  7. INC SI: increase value of SI by 1
  8. CMP AL, [SI]: compares value of register AL and [SI] (AL-[SI])
  9. JNC 413: jump to address 413 if carry not generated
  10. MOV AL, [SI]: transfer data at offset SI to register AL
  11. INC SI: increase value of SI by 1
  12. LOOP 40C: decrease value of register CX by 1 and jump to address 40D if value of register CX is not zero
  13. MOV [600], AL: store the value of register AL to offset 600
  14. HLT: stop





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.