English

Write an ALP to count the number of odd data byte occurring in a block, starting from memory location 2501H to 25FFH. Store the result at the memory location 2600H.

Advertisements
Advertisements

Question

Write an ALP to count the number of odd data byte occurring in a block, starting from memory location 2501H to 25FFH. Store the result at the memory location 2600H.

Code Writing
Advertisements

Solution

        LXI H, 2501H      ; HL points to start of block
        MVI B, FFH        ; Counter = FFH (2501H to 25FFH = 255 bytes)
        MVI D, 00H        ; D = count of odd numbers

LOOP:   MOV A, M          ; A = data byte
        ANI 01H           ; Check LSB
        JZ NEXT           ; If LSB=0, it's even -> skip
        INR D             ; If odd, increment count

NEXT:   INX H             ; Next memory location
        DCR B             ; Decrement counter
        JNZ LOOP          ; Repeat till all bytes checked

        MOV A, D          ; A = count
        STA 2600H         ; Store result at 2600H
        HLT
shaalaa.com
  Is there an error in this question or solution?
2021-2022 (March) Set 1

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×