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 zero, negative and positive numbers in a given series.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Negative numbers are represented by (MSB of 1/D7-1) and positive numbers are represented by (MSB-0/D7-0). In this program we have to store length of series also. Store the counts in memory locations 2600, 2601 and 2602 H.
Algorithm:
  • Load Length of the series into Accumulator and set as counter as length of series
  • Initialize counter to store number of zero, negative and positive numbers
  • Get the first number in accumulator and check number is zero. If number is zero then increment the counter to store count of zero
  • If number is 1 then increments the negative number counter else increment the positive number counter.
  • Increment the pointer
  • Check the counter if counter is not zero then repeats the process.
  • Store output at given location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2500 H
Length of series in A
2003
MOV
C,A
Initialize C as the Counter for all no.  
2004
MVI
B,00 H
Initialize B for counting negative no
2006
MVI
E,00 H
Initialize E for counting zeros no
2008
MVI
D,00 H
Initialize D for counting positive no
200A
LXI
H,2501 H
Initialize memory pointer
200D
MOV
A,M
Get number from series
200E
CPI
00 H
Compare it with 00 H
2010
JZ
201B
If it is equal to zero, jump to  201B
2013
RAL

Rotate accumulator left with carry
2014
JC
201F
If the no. is negative then jump to 201F
2017
INR
D
If not –ve then increase the counter of +
2018
JMP
2020
Jump to 2020
201B
INR
E
Increment zero counter
201C
JMP
2020
Jump to 2020
201F
INR
B
Increment negative number counter
2020
INX
H
Increment the pointer
2021
DCR
C
Decrement Counter
2022
JNZ
200D
If counter is not 0,repeat process
2025
LXI
H,2600 H
If it is =A then initialize HL pair to store count
2028
MOV
M,B
Store the count of negative number
2029
INX
H
Increment HL register pair
202A
MOV
M,E
Store the count of 0
202B
INX
H
Increment HL register pair
202C
MOV
M,D
Store the count of positive number
202D
RST
5
Set Break Point
202E
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.
JC: Jump if carry at specified memory address.
JMP: Jump unconditionally
CPI: This instruction is used to compare the data with accumulator
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-00 H
2503-73 H
2504-82 H
Output:
2600- 01(Negative number)
2601-00 (Zero)
2602-02 (positive 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