[A83] Re: quick data storage question
[Prev][Next][Index][Thread]
[A83] Re: quick data storage question
Well, except it would be .dw $3 instead of .dw $0 in your example...
To clarify, db is define byte and dw is define word (or some people think
it's data instead of define, but that's really an irrelevent consideration).
db can be used to define individual bytes or character strings, while dw's
main use is for defining addresses. What's tricky about dw is that the z80
processor is little endian, which means that when you store 16-bit values in
memory the lower byte is stored first, then the higher byte. For example:
.dw $abcd
Is the same as
.db $cd,$ab
A typical use of dw would be like this.
goto_table_address:
;de->table of addresses
;a = # of address to jump to
ld l,a
ld h,0 ;put number in hl
add hl,hl ;since pointers are 2 bytes, we double the #
add hl,de ;add to table pointer
jp (hl) ;jump to pointer
With a table something like this:
jump_table:
.dw label1
.dw label2
.dw label3
.dw label4
Also, dw can be used for 16-bit values like scores or coordinates or such.
Just be careful not to start using dw when you only use 8-bit values.
In a message dated 4/15/2001 5:23:04 AM Eastern Daylight Time,
dArkSk8eR@buffbody.com writes:
> ".db" defines 1 byte i.e.
> .db $3 = $03 in ram
> ".dw" defines 2 bytes i.e.
> .dw $0 = $0003 in ram
----
Jonah Cohen
<ComAsYuAre@aol.com>
http://jonah.ticalc.org