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

Re: A85: Vars




On Mon, 9 Mar 1998, GrafixxHQ wrote:
> I am a little confused about variables stored in the game itself, and how to
> retrieve that info.
> 
> ( i )  How do you retrieve variables stored in, say, this:   
> Variable:
>   .db 0
Easy, use the ld instruction.
  ld a,(Variable)
this would load whatever byte you have defined, in this case 0 into the A
register.
What you're really saying is put what is at the address Variable into A.
when you write 
Varaible:
you are just giving the address another name.  So you could also do
something like this:
  ld a,($FC01)

> ( ii ) How do you store multiple variables in label?  Is it something like:
> Variables:
>   .db 0,0,0,0
> 
> ( iii )  How do you retrieve these?  Also, once you have recieved one and put
> it in a register or someything to be held, how would you get to the next one? 
Same idea,
  ld a,(Variables)   ;for the first one
  ld a,(Variables+1) ;for the second
 ...

Once you understand the concept of what you are doing it's easy.  I'll put
it in terms that I understand.
Your program is just a string of numbers ranging from 0 to 255.  The Z80
can read interpret these and do something or it can read from it and use
the value to do some operation or it can change it to something else.
When you're storing a variable in the program what you do is refer to some
of the numbers in your program as information and not as code.

I think I'll stop there.  If you're still confused, (probably), be more
specific about what confuses you.

-Humberto



References: