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 find numbers of positive numbers in a given series.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Negative numbers are represented by (MSB of 0/D7-0). In this program we have to store length of series also.
 
Algorithm:
  • Load Length of the series into Accumulator and set as counter
  • Initialize register to store the number of positive number
  • Get the first number in accumulator
  • Check for MSB, if the value of MSB is equal to 0 then number is positive
  • If number is positive then Increment register to store count
  • If number is not positive then process till length of series is 0
  • Store output at given location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2500 H
Length of series in Acc.
2003
MOV
C,A
Initialize C as the Counter  
2004
MVI
B,00 H
Initialize B as 00 for count
2006
LXI
H,2501 H
Initialize memory pointer
2009
MOV
A,M
Get number from series
200A
RAL
Rotate accumulator left
200B
JC
200F
Check MSB is equal to 1 or not
200E
INR
B
If MSB=1 then Increment B
200F
INX
H
Increment the pointer
2010
DCR
C
Decrement Counter
2011
JNZ
2009
If counter is not 0,repeat process
2014
MOV
A,B
If counter is zero then store B
2015
STA
2550 H
Store output
2018
RST
5
Set Break Point
2019
END
End the program

Used Instruction:  
LDA address: Load data into register A (accumulator) directly from the address given within the instruction. 
MOV rd, rs: This instruction copies data from the source register into destination register. 
MVI: This instruction is used to store the 8 bit data in specified register. 
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand. 
RAL: Rotates the bits of accumulator left by one position, through the carry 
JNC: Jump if not carry at specified memory address. 
INR: It will increment the content of specified register by one. 
DCR: It will decrement the content of specified register by one. 
JNZ: If result is not zero it will jump to the target address. 
INX: This instruction is used to increment the content of register pair 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:  
2500-04 H (Length of series) 
2501-56 H 
2502-A9 H 
2503-73 H 
2504-82 H 
Output: 
2550- 02 (56 and 73 H are negative number)
 
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 (M2500)
  • Press ENTER and Provide your Input at location (2500:04)
  • Press ENTER and Provide your Input at location (2501:56) 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 (M2550) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment