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

Aim: Write a program to find Square of a given number and store output at external memory 4001H.
Apparatus Used: Micro-controller kit.
Assumption: The Square of a number can be calculated by adding consecutive odd numbers starting from 1. In order to find the square of 3, add three odd numbers starting from 1. 1 + 3 + 5 = 9.
To find the Square of 4, 1 + 3 + 5 + 7 = 16.
Algorithm:
  • 1.Set the input location.
  • 2.Move first number into the accumulator.
  • 3.Check the number in accumulator is zero or not zero.
  • 4.If zero then store output otherwise move forward.
  • 5.Set the number who’s Square is to be calculated as the counter.
  • 6.Get the first odd number.
  • 7.Clear the accumulator to store output.
  • 2.Add odd numbers starting from zero until counter is zero.
  • 8.Store the output.
Program:
Description of used instruction:
MOV: Used for Load and Copy the Data. This copies a byte from the source location to destination.
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 A.
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 basically used to end the program.
JZ: This instruction examines the contents of the accumulator and jump to target if its value is 0.
INC: This instruction adds 1 to the register or memory location specified by the operand.

Result:
Input:  4000-05
Output: 4001-19 (19H=25 D)
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 to find Square.
·         Press Enter two times again.
·         Press G and provide starting address 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 4001H and Press Space and you get Output.

Continue 
 

No comments:

Post a Comment