Skip to main content

8085 ALP: transfer with bit set/reset

Short answer

Compare each byte with 80H. If less (carry set), set bit D5 with ORI 20H; otherwise reset bit D6 with ANI BFH. Transfer ten numbers to a second table. Example: 12H becomes 32H, C5H becomes 85H.

Write a program in 8085 to transfer 8-bit number from one table to other by setting bit D5 if the number is less than 80H else transfer the number by resetting bit D6.

Compare each number with 80H using CPI 80H: carry is set when the number is less than 80H. If less, set D5 (OR with 20H); otherwise reset D6 (AND with BFH = 1011 1111). Then store it in the second table.

Assumptions: the table has 10 numbers; source table at 2000H, destination at 3000H (any addresses can be used).

        LXI  H,2000H      ; HL = source table
        LXI  D,3000H      ; DE = destination table
        MVI  C,0AH        ; number of bytes = 10
NEXT:   MOV  A,M          ; A = number
        CPI  80H          ; compare with 80H (A - 80H)
        JC   LESS         ; CY=1 -> number < 80H
        ANI  0BFH         ; number >= 80H : reset bit D6
        JMP  STORE
LESS:   ORI  20H          ; number < 80H : set bit D5
STORE:  STAX D            ; store into second table
        INX  H            ; next source byte
        INX  D            ; next destination byte
        DCR  C            ; decrement counter
        JNZ  NEXT         ; loop until all bytes are done
        HLT

Examples: 12H (< 80H) becomes 12H OR 20H = 32H. C5H (≥ 80H) becomes C5H AND BFH = 85H.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →