Skip to main content

8085 ALP: copy data within a range

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.

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.

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.

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

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →