Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Addition of natural numbers

Written by @
Aim: Write a program to add first 10 natural number and store output at external memory 3020H.
Apparatus Used: Micro-controller kit.
Assumption:  The first 10 natural numbers are 1, 2, 3……10. We have write a program to add this.
Algorithm:
  • Firstly clear the contents of accumulator.
  • Load number of bytes (Counter)  in Register R2.
  • Initialize R0 as zero.
  • Increment R0 to get first natural numbers.
  • Now Add R0 to accumulator.
  • Add till R2=0.
  • Initialize memory location to store output.
  • Store output at given location. 
Program:
  
Description of used instruction:
MOV: Used for Load and Copy the Data. This copies a byte from the source location to destination. 
INC: This instruction adds 1 to the register or memory location specified by the operand. 
ADD: This adds the source byte to the accumulator and keeps result in accumulator. 
DJNZ: In this instruction a byte is decremented, and if result is not zero it will jump to the target address. 
MOVX: This instruction transfer data between external memory and register. 
DPTR: This is Data Pointer. It is used for containing 16 bit data or memory address. 
SJMP: Short Jump loop is used for indefinite loop within program.

Result:
Input: 1, 2,3,4,5,6,7,8,9,10 
Output:  1+2+3+4+5+6+7+8+9+10=55 (37H) and it will store at external memory 3020H.
Procedure to look output:
·         After ending (SJMP) the program, press Enter two times.
·         You will get message “Welcome to ------KIT”.
·         Press G and Provide initial address of program as in this program, starting address is 3000 H.
·         Press Enter.
·         After pressing Enter, You will get Message “Execution Completed”.
·         Press Reset on micro-controller KIT.
·         Press M and You will get Message “Enter Address”.     
·         Provide Address for Output as in this Program 3020H and Press Space and you get Output.


1 comment:

  1. please allow the option of copying the text

    ReplyDelete