Re: A83: hl / (hl) ???


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

Re: A83: hl / (hl) ???




In a message dated 1/27/00 12:17:31 PM Eastern Standard Time, 
marcputs@hetnet.nl writes:

> Sorry I'm asking so much, but I think it's the best way to learn ASM!
>  
>  What's the difference between hl and (hl) ?
>  

hl can be used for two things -- as a value and an address.

When hl is a value, then hl represents a 16-bit number.  For example, ld 
hl,683 means that hl=683 (go figure).

If hl is used as a pointer, than you will want to be able to access what hl 
points to (because that's the whole point, right?  :P).  To access the byte 
pointed to by hl, you use parenthesis, such as ld a,(hl).  Other 16-bit 
registers such as de and bc can be used for addressing in this manner as well.

This is an example of how you could copy a zero-terminated string from the 
label "string" to whatever de points to:

 ld hl,string           ;hl points to string
copy_loop:
 ld a,(hl)          ;a is the byte pointed to by hl
 or a               ;check for 0
 ret z              ;done
 ld (de),a          ;the value pointed to by de now contains what is in a
 inc hl             ;increment pointer to next byte
 inc de             ;increment other pointer
 jr copy_loop       ;repeat until we reach a 0


You can do a lot of cool instructions with (hl).  In fact, the z80 chip 
supports it as it does all the basic registers.  So you can do things like 
this:

 rr (hl)                ;rotate byte pointed to by hl to the right
 cp (hl)                ;compare a to the byte pointed to by hl
 or (hl)                ;bitwise or a with the byte pointed to by hl

...and many other instructions.


----
Jonah Cohen
<ComAsYuAre@aol.com>
http://linux.hypnotic.org/~jonah/