English

Write an Assembly Language Program to count number of times data D9H present in a memory block begins from C400H. The length of the block is stored at C3FFH. Store the result after end of the block.

Advertisements
Advertisements

Question

Write an Assembly Language Program to count number of times data D9H present in a memory block begins from C400H. The length of the block is stored at C3FFH. Store the result after end of the block.

Code Writing
Advertisements

Solution

Label           Mnemonics+ operand                          Comments

START:  LXI H, C3FFH     ; Initialize H-L pair with starting address
        MOV C, M         ; Store count in register C
        MVI B, 00H       ; Initialize occurrence count in register B
        INX H            ; Increment memory location

LOOP:   MOV A, M         ; Get number in accumulator
        CPI D9H          ; Compare with D9H
        JNZ NEXT         ; If not equal, jump to NEXT
        INR B            ; If equal, increment B

NEXT:   INX H            ; Increment H-L pair
        DCR C            ; Decrement count
        JNZ LOOP         ; If count not zero, repeat loop
        INX H            ; Increment memory location
        MOV M, B         ; Store occurrence count in memory

END:    HLT              ; Stop processing
shaalaa.com
  Is there an error in this question or solution?
2022-2023 (March) Official
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×