---
title: "8085 ALP: add upper and lower nibbles"
subject: "Microprocessor"
chapter: 2
key: "semester_4/microprocessor:alp-8085-add-nibbles"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-add-nibbles
site: BCT Engineering
---

# 8085 ALP: add upper and lower nibbles

Microprocessor · Chapter 2: Programming with 8085 Microprocessor

- Asked in: 2071 Bhadra, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-add-nibbles
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-2

## Question

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.

## 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.

## Answer

**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).


```asm
        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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which instruction separates the lower nibble of the byte in A?
   A. ANI 0F0H
   B. ORI 0FH
   C. ANI 0FH
   D. XRI 0FH
   Answer: C. ANDing with 0FH clears bits D7-D4 and keeps D3-D0, leaving only the lower nibble. (Key point: ANI 0FH isolates the lower nibble)

2. For the byte 5AH, how does the program get the upper nibble value 05H?
   A. ANI 0F0H gives 50H, then four RRC instructions move it to 05H
   B. ANI 0FH gives 0AH, then four RLC instructions give 05H
   C. ANI 0F0H gives 50H, which is added directly as 05H
   D. One RRC instruction moves the upper nibble down
   Answer: A. ANI 0F0H keeps only the upper nibble (50H). Each RRC rotates right by one bit, so four RRCs move it to the lower position (05H) before it is added. (Key point: Upper nibble: ANI F0H then four RRC to bring it to the low position)

3. What is the largest possible result, and where is the result for the byte at 8B25H stored?
   A. FFH; at 8B26H
   B. 0FH; at 8B2FH
   C. 1EH (0FH + 0FH); at 8B2AH
   D. 1EH (0FH + 0FH); at 8B2FH (8B25H + 0AH)
   Answer: D. Each nibble is at most 0FH, so the sum is at most 1EH and fits in one byte. Results start at 8B2AH, just after the table, so each one is at its source address + 0AH. (Key point: Each result is at most 1EH and goes at source address + 0AH)

## Related in Microprocessor

- [8085 ALP: count ones in upper nibble](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-upper-nibble) — Microprocessor, chapter 2
- [8085 ALP: square of ten numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-square-numbers) — Microprocessor, chapter 2
- [8085 ALP: multiplication table of a number](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-multiplication-table) — Microprocessor, chapter 2
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [8085 ALP: add two tables, sum and carry](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-add-two-tables) — Microprocessor, chapter 2
- [8085 ALP: odd parity transfer with bit change](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-odd-parity-transfer) — Microprocessor, chapter 2
