Re: A86: more info needed on ld command


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

Re: A86: more info needed on ld command



On Thu, 11 Sep 1997, Butler Family wrote:

> > ld (hl),nn  loads nn into the memory location whose
> >             address is stored in hl
> 
> what is the use of loading it into the memory location if u can do the
> basically same thing w/o parentheses? or would it keep the hl from
> moving its location in the memory?and one last question what would it do
> if u did ld nn,(hl)? would it make nn equal to the memory location or
> save it as hl and have be where hl was?


I think there's a fundamental misunderstanding here, but I'll try to
explain clearly.

"LD (HL),nn" and "LD HL,nnnn" are NOT basically the same thing.  HL is a
register, which is a storage space completely separate from memory.  If
you're used to programming in almost any high-level language, you're
probably getting confused by thinking of HL as a variable.  Don't.

"LD HL,nnnn" stores the value nnnn into the register HL.
"LD (HL),nn" stores the value nn into the memory address HL points to

Here's an example to help sort things out:

	LD HL,$C008
	LD (HL),$2A

After the first instruction, HL=$C008.  After the second instruction, byte
$C008 in RAM holds the value $2A.

"LD nn,HL" is not a valid instruction, because you can't store into a
constant.

I hope this has been beneficial.

--------
Dan Eble (mailto:eble@cis.ohio-state.edu)
         (http://www.cis.ohio-state.edu/~eble)


References: