# How can read 16 bit address from db table?

I everybody,
My question is to read 16 bit address from db table.
This is my listing, but t'is wrong.
My desire is also to assign "alias" in db list like showed in the same example (ALIAS should be another 16 bit address).

Thanks.

ld b,\$2
ld IX,Sequence
CicloMain:
ld B,(IX+\$1)
ld C,(IX+\$0)
INC IX
INC IX
DJNZ CicloMain
ret
Sequence:
db \$1122,\$3344,\$8866,ALIAS

You must use "dw" to define 16-bit values, not "db".

Also, as your list gets longer the number of iterations gets quite costly. Better to multiply the index by two (left-shift or add with self), and then add it to the base address:

```    ld bc,2
ld ix,Sequence
add ix,bc         ; + index * 2
ld c,(ix + 0)
ld b,(ix + 1)
ret

Sequence:
dw 1122H, 3344H, 5566H, 7788H
```

Or if the table is less than 128 entries, I guess pretend you're a 6502:

```    ld bc,2
ld ix,Sequence
add ix,bc         ; + index
ld c,(ix + 0)
ld b,(ix + SequenceHigh - SequenceLow) ; assuming SequenceHigh - SequenceLow is less than 128
ret

SequenceLow:
db 22H, 44H, 66H, 88H
SequenceHigh:
db 11H, 33H, 55H, 77H
```

Somebody soon will point out that using a different combination of registers — HL in particular — is faster, I'm sure, but that'd have wider effect. I've already made one assumption that isn't necessarily valid and which Grauw declined to.

There are too many ways to micro-optimise (and obfuscate) it further that I decided to just mention the algorithmic optimisation .

Thanks! Thanks! Thanks!

Right — nobody's going to beat turning O(n) into O(1) with a seven-line direct drop-in replacement. You've out computer scienced us all!