---
title: "8085 ALP: copy data within a range"
subject: "Microprocessor"
chapter: 2
key: "semester_4/microprocessor:alp-8085-copy-range"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-copy-range
site: BCT Engineering
---

# 8085 ALP: copy data within a range

Microprocessor · Chapter 2: Programming with 8085 Microprocessor

- Asked in: 2068 Magh, 8 marks
- Video: [8085 program to transfer a block of data|Transferring a block of Data in 8085|Copy a block of data](https://www.youtube.com/watch?v=csDsuQm0Ijg) — Scratch Learners
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-copy-range
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-2

## Question

Ten no. of 8-bit data is started in memory at A000H. Write a program for 8085 microprocessor to copy the data to next table at A030H if the data is less than 70H and greater than 24H.

## Short answer

Compare each byte: CPI 70H, skip if no carry (≥70H) using JNC; CPI 25H, skip if carry (<25H) using JC. Only bytes from 25H to 6FH are stored at A030H, advancing the destination pointer only when a byte is copied.

## Answer

Data is copied only if 24H < data < 70H, i.e. 25H ≤ data ≤ 6FH. Two compares are used:
- `CPI 70H` : no carry means data ≥ 70H, so skip.
- `CPI 25H` : carry means data < 25H (data ≤ 24H), so skip.

The destination pointer advances only when a byte is copied, so the selected bytes are stored consecutively from A030H.

```asm
        LXI  H,0A000H     ; HL = source table
        LXI  D,0A030H     ; DE = destination table
        MVI  C,0AH        ; ten data bytes
NEXT:   MOV  A,M          ; A = data
        CPI  70H          ; A - 70H
        JNC  SKIP         ; A >= 70H -> not in range
        CPI  25H          ; A - 25H
        JC   SKIP         ; A < 25H (i.e. <= 24H) -> not in range
        STAX D            ; 25H <= A <= 6FH : copy
        INX  D            ; advance destination only on copy
SKIP:   INX  H            ; next source byte
        DCR  C
        JNZ  NEXT
        HLT
```

**Example:** data 10H, 30H, 24H, 25H, 70H, 6FH, 90H ... → copied bytes are 30H, 25H, 6FH (24H and 70H are excluded since the limits are strict).

## Check yourself

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

1. Which data values are copied when the data must be less than 70H and greater than 24H?
   A. 24H to 70H, both included
   B. 25H to 6FH, both included
   C. 24H to 6FH
   D. 25H to 70H
   Answer: B. Both limits are strict, so 24H and 70H are excluded. The copied range is 25H <= data <= 6FH. (Key point: Strict limits: copy only 25H to 6FH)

2. After CPI 70H, why does the program use JNC SKIP?
   A. No carry means A < 70H, which is out of range
   B. No carry means A = 70H only
   C. CPI 70H changes A, and JNC checks the new value
   D. No carry means A >= 70H, which is out of range
   Answer: D. CPI works out A - 70H. A borrow (CY = 1) happens only when A < 70H, so no carry means A >= 70H, which is outside the range. (Key point: CPI 70H with JNC skips data >= 70H)

3. Why is the lower check written as CPI 25H followed by JC SKIP?
   A. CY = 1 means A < 25H (A <= 24H), so 24H and below are skipped
   B. To include 24H in the copied data, as the question requires
   C. Because JC jumps when A is greater than the operand
   D. Because CPI can only compare with odd immediate values
   Answer: A. CPI 25H sets CY when A < 25H. Skipping on carry rejects every value up to 24H, so only values above 24H are copied. (Key point: CPI 25H with JC skips data <= 24H)

4. Why is INX D placed before SKIP and not after it?
   A. So DE always stays exactly 30H ahead of HL
   B. Because STAX D needs DE to be incremented first
   C. So DE moves only when a byte is copied, keeping the copies consecutive
   D. To count how many bytes were skipped
   Answer: C. Skipped bytes jump straight to SKIP, past INX D, so the destination pointer moves only after STAX D. The copied bytes therefore fill A030H onwards with no gaps. (Key point: The destination pointer advances only when a byte is copied)

## Related in Microprocessor

- [8085 ALP: transfer data with more than 3 ones](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-greater-than-3) — 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: square of ten numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-square-numbers) — Microprocessor, chapter 2
- [8085 ALP: transfer with bit set/reset](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-set-reset-bit-80h) — 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
- [8085 ALP: multiplication table of a number](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-multiplication-table) — Microprocessor, chapter 2

## Related in other subjects

- [3-phase IM principle; speed less than sync](https://www.bctengineer.com/question.md?key=semester_4%2Felectrical_machine%3Athree-phase-im-principle-slip) — Electrical Machine, chapter 5
- [Detection gain of DSB-AM is less than 1](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Adetection-gain-dsbam-less-than-1) — Communication Systems, chapter 9
- [When terminal voltage is less or more than emf](https://www.bctengineer.com/question.md?key=semester_5%2Felectric_machines_ii%3Aterminal-voltage-less-or-more) — Electric Machines II, chapter 1
- [True/false: series motor started at no load](https://www.bctengineer.com/question.md?key=semester_4%2Felectrical_machine%3Atf-dc-series-motor-start-noload) — Electrical Machine, chapter 4
