February 28, 2012
Write an assembly language program to count the number of 0’s in any given 8-bit data.
Apparatus Used: Microprocessor Kit, Keyboard
Used Instruction:
Assumption: This program uses a counter to check all the eight bits of the number
Algorithm:
- Load number into accumulator
- Initialize a register to store number of 0
- Initialize a register as counter
- Rotate right the content of accumulator
- Check for 0,if bit is 0 then Increment register to store count
- Decrement C if counter is zero then proceed next step
- Store output
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LDA
|
2500 H
|
Get First Number in Acc.
|
2003
|
MVI
|
B,00 H
|
Initialize B as 00 for count
|
2005
|
MVI
|
C,08 H
|
Initialize as counter
|
2007
|
RAR
|
Rotate right accumulator
| |
2008
|
JC
|
200C
|
If bit is not 1 then go to 200C
|
200B
|
INR
|
B
|
If bit is 1,Then increment B
|
200C
|
DCR
|
C
|
Decrement counter C
|
200D
|
JNZ
|
2007
|
If C is not 0 then jump 2007
|
2010
|
MOV
|
A,B
|
Save data of B into A
|
2011
|
STA
|
2501 H
|
Store output
|
2014
|
RST
|
5
|
Set Break Point
|
2015
|
END
|
End the program
|
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.
RAR: Rotates the bits of accumulator right by one position, through the carry
JC: Jump if 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.
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-34
Output:
2501-05
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:34)
- 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 (M2501) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment