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 only even number 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. In this program we have to ignore carry and output will be eight bit only. The result of sum is stored in memory location 2500 H.
Algorithm:
  • Initialize counter as length of series
  • Initialize B register to store output
  • Get first data
  • Load first data in accumulator
  • Rotate right through carry
  • Check for carry, if carry bit is 1 then data is odd otherwise even
  • If number is even load sum in A
  • Add accumulator and data from the series
  • Store the result in register B
  • Check counter for zero, if not zero then repeat the process and so on
  • Store output
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2300 H
Load length of series in A
2003
MOV
C,A
Initialize counter as C
2004
MVI
B,00 H
Initialize sum=0
2006
INX
H
Get first data
2007
MOV
A,M
Load first data in Accumulator
2008
RAR

Rotate right to check LSB of data
2009
JC
200F
Add if number is even,LSB=0
200C
MOV
A,B
If number is even, load sum in A
200D
ADD
M
Sum=sum +  data from series
200E
MOV
B,A
Store the result in B
200F
INX
H
Increment Pointer
2010
DCR
C
Decrement counter
2011
JNZ
2007
Repeat process till counter=0
2014
STA
2500 H
Store output
2017
RST
5
Set Break-point
2018
END

End the program

Used Instruction:
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
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.
RAR: Rotates the bits of accumulator right by one position, through the carry
JC: Jump if carry at specified memory address.
DCR: This instruction is used decrement the content of specified register by 1.
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 (Length of series)
            2301 H-01 H
            2302 H-02 H
            2303 H-03 H
            2304 H-04 H
Output: 2500-06 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:01H)
  • Press ENTER and provide your Input at location (2302:02H) 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