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

Write an assembly language program to calculate the sum of series of 8-bit numbers, output 8-bit number

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: In this program the length of series is in memory location 2300 H and series itself begins from memory location 2301 H. The result of sum is stored in memory location 2500 H.
Algorithm:
  • Load the length of the array in accumulator
  • Initialize counter
  • Clear accumulator
  • Get first data and add the first data with accumulator
  • Increment the Pointer
  • Decrement counter
  • Check counter for zero, if not zero then add next number and so on
  • Store output
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2300 H
Load length of array in Accumulator
2003
MOV
C,A
Initialize counter as A
2004
XRA
A
Make sum=0
2005
LXI
H,2301 H
Get first data
2008
ADD
M
Add first data to accumulator
2009
INX
H
Increment the Pointer
200A
DCR
C
Decrement counter
200B
JNZ
2008
Check for counter
200E
STA
2500 H
Store output
2011
RST
5
Set the Breakpoint
2012
END

End the program
Used Instruction:
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
XRA: Logically AND the contents of register/memory with the accumulator.
MVI: This instruction is used to store 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
INX: This instruction is used to increment the content of register pair by 1.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: Jump if value of specified register is not zero.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result: 
Input: 2300 H-04 H
            2301 H-01 H
            2302 H-02 H
            2303 H-03 H
            2304 H-04 H
Output: 2500-0A H            
Procedure to look output
  • After press ENTER, You will get first screen
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4, you will get first screen again
  • Press M and Provide Input location for Input (M2300)
  • Press ENTER and provide your Input at location (2300:04H)
  • Press ENTER and provide your Input at location (2301:9AH)
  • Press ENTER and provide your Input at location (2302:52H) and so on…
  • Press SHIFT+4
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide address for output (M2500) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment