Advertisements
Advertisements
Question
Write an Assembly Language Program to count the number of times data 9DH is found in block of memory locations starting from 8901H. Length of the block is stored in memory location 8900H. Store the result in memory location 8000H.
Code Writing
Advertisements
Solution
; 8085 Program to count occurrences of 9DH in a memory block
; Block length is at 8900H, Block starts from 8901H
; Result is stored at 8000H
Label Instructions Comments
LXI H, 8900H ; Set HL to 8900H
MOV B, M ; Move M to B
MVI C, 00H ; Set C to 00H
LOOP: INX H ; Increment HL by 1
MOV A, M ; Move M to A
CPI 9DH ; Compare 9DH with A
JNZ SKIP ; Jump not zero go to SKIP
INR C ; Increment C by 1
SKIP: DCR B ; Decrement B by 1
JNZ LOOP ; Jump not zero go to LOOP
MOV A, C ; Move C to A
STA 8000H ; Store content of A to 8000H
HLT ; Stop
shaalaa.com
Is there an error in this question or solution?
