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

Addition of n byte using microcontroller

Written by @
Aim: Write an Assembly language program to add ‘n’ bytes stored in external memory (Starting address 4000 and number of bytes is 5) and store output at 3020H.
Apparatus Used: Micro-controller kit.
Assumption:  In this program we have to add n bytes number. Means there are 5 numbers which are stored at different memory location; we have store output at 3020 H.
  • Load number of bytes in Register R0.
  • Initialize R1 as 00.
  • Initialize memory location to store input at memory location.
  • Move the first number into accumulator.
  • Now add R1 to accumulator.
  • Increase pointer to point next number.
  • Repeat this till R2=00
  • Initialize memory location to store output.
  • Store output at given location. 

Description of used instruction:
MOV: Used for Load and Copy the Data. This copies a byte from the source location to destination. 
INC DPTR: This instruction increments the 16-bit register DPTR (Data Pointer) by 1. Notice that DPTR is the only 16-bit register that can be incremented. 
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.


Input:    4000-01H
Output:  0BH 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 Location of Input as in this program 4000H. Press Space and write a number as first input,press Space again and enter 2nd input as so on for 5 inputs.
·         Press Enter two times again.
·         Press G and provide starting address (3000H)  and Press Enter.
·         You will Get Message “Execution Completed”.
·         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.

    No comments:

    Post a Comment