- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 program to find the sum of first n natural numbers
In this program we will see how to add first n natural numbers.
Problem Statement
Write 8085 Assembly language program to add first N natural numbers. The value of N is provided.
Discussion
We are getting the value of N from memory location 8000H. We are using the number N as count variable, in each step we are calculating (A + Count) value, and store them into A. After adding them, the count value is decreased,thus the total series is completed.
If the number is 23H(35D), then the sum will be (35*36)/2 = 630 (276H)
Input
Address | Data |
---|---|
. . . | . . . |
8000 | 23 |
. . . | . . . |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | LXI H,8000H | Point to get the upper limit | |
F003 | 4E | MOV C, M | Load the upper limit to C | |
F004 | AF | XRA A | Clear the A register | |
F005 | 47 | MOV B, A | Also clear B register | |
F006 | 81 | LOOP | ADD C | Add C with A |
F007 | D2, 0B, F0 | JNC SKIP | If CY = 0,Skip next step | |
F00A | 04 | INR B | Increase B ifCY = 1 | |
F00B | 0D | SKIP | DCR C | Decrease C by1 |
F00C | C2, 06, F0 | JNZ LOOP | Until Z = 1,go to LOOP | |
F00F | 21, 50, 80 | LXI H, 8050H | Point to the destination address | |
F012 | 77 | MOV M, A | Store the acc content | |
F013 | 23 | INX H | Point to next location | |
F014 | 70 | MOV M, B | Store the MSbyte | |
F015 | 76 | HLT | Terminate the program |
Output
Address | Data |
---|---|
. . . | . . . |
8050 | 76 |
8051 | 02 |
. . . | . . . |
- Related Articles
- Program to find sum of first n natural numbers in C++
- Find the sum of first $n$ odd natural numbers.
- PHP program to find the sum of cubes of the first n natural numbers
- Java Program to cube sum of first n natural numbers
- Sum of first n natural numbers in C Program
- PHP program to find the sum of the 5th powers of first n natural numbers
- Swift Program to Calculate Cube Sum of First n Natural Numbers
- C Program for the cube sum of first n natural numbers?
- Java program to find the sum of n natural numbers
- Python Program for cube sum of first n natural numbers
- C Program for cube sum of first n natural numbers?
- C++ Program for cube sum of first n natural numbers?
- PHP program to calculate the sum of square of first n natural numbers
- Java Program to calculate Sum of squares of first n natural numbers
- Python Program for Sum of squares of first n natural numbers

Advertisements