[A83] Re: .dw -> .db +call _ldhlind


[Prev][Next][Index][Thread]

[A83] Re: .dw -> .db +call _ldhlind




Think about what really happens in assembler.  When you load text into hl,
you are loading the value of text, which is the address of the pointer
othertext.  So you have something that looks like:

text = $9000
9000: .dw $9002       ; $02, $90
9002: "Hi!", 0

So your code is doing this:

 ld hl,$9000

Once you have text, you need to get the value at that location:

 ld hl,text
 ld a,(hl)
 inc hl
 ld h,(hl)
 ld l,a

Or, without labels:

 ld hl,$9000    ; point to $9000
 ld a,(hl)          ; load $02
 inc hl              ; point to $9001
 ld h,(hl)          ; load $90 (H = $90, L = xx)
 ld l,a              ; load $02 (H = $90, L = $02)

The load is done in the order shown, because words are stored with the least
significant byte (the low byte) first in memory (low address first).  This
is known as little-endian, because the little end is stored first.  You can
remember this by thinking little-endian = little-end-first.  This is the
same as x86 cpu's.  Motorola 68k and PPC, Sparc and most non-DEC mips cpu's
are big-endian, which store the big end first, or the most significant byte
first (backwards from z80).

> Could somebody explain why this doesn't only display the text with the
.dw??
>
> call _clrscrnfull
> call _homeup
> ld hl,text
> jp _puts
>
> text: .dw othertext
> othertext: .dw txt
> txt: .db "Hi!",0





References: