Skip to main content

8085 ALP: add upper and lower nibbles

Short answer

Lower nibble obtained with ANI 0FH; upper nibble isolated with ANI F0H and shifted right by four RRC instructions. Add the two nibbles and store each sum at a location offset by +0AH from the source byte. Example: 5AH yields 0FH.

Write a program for 8085 to add the upper and lower nibble of ten 8 bit words stored in a table, that starts from location 8B20H. Store the separate results in locations just after the table.

Assumptions: the 10 bytes are at 8B20H-8B29H; the results (each at most 1EH) are stored at 8B2AH-8B33H, starting just after the table, one result per byte.

Method: the lower nibble is separated with ANI 0FH. The upper nibble is separated with ANI F0H and moved to the lower position with four RRC instructions. The two nibbles are added. The result address is the source address + 0AH, obtained by changing L only (no page crossing here).

        LXI H,8B20H     ; HL -> table (8B20H..8B29H)
        MVI C,0AH       ; 10 bytes
LOOP:   MOV A,M
        MOV B,A         ; save byte
        ANI 0FH         ; lower nibble
        MOV D,A         ; D = lower nibble
        MOV A,B
        ANI 0F0H        ; upper nibble
        RRC             ; bring it to the lower position
        RRC
        RRC
        RRC
        ADD D           ; upper + lower
        MOV E,A         ; E = sum
        MOV A,L
        ADI 0AH         ; L + 10 -> result area (8B2AH + i)
        MOV L,A
        MOV M,E         ; store result
        SUI 09H         ; A = old L + 1
        MOV L,A         ; next byte
        DCR C
        JNZ LOOP
        HLT

Example: byte 5AH gives 5 + A = 0FH.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →