CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 85 users online: 4 members, 57 guests and 24 bots.
Members: blue_bear_94, parrotgeek1, rfdave.
Bots: MSN/Bing (1), VoilaBot (1), Googlebot (20), MSN/Bing (2).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55773
Location: Earth, Sol, Milky Way

Posted: 10 Sep 2006 09:51:08 am    Post subject: Indirection

Q: What's with the parentheses sometimes used with ld?
A: OK, this is because of something called indirection. For simplicity's sake, let's assume you have a piece of memory that can hold exactly 2^16th bytes (sets of 8 bits). That means that you can 'address' the memory by assigning each of the 2^16 bytes with a number between 0 and 65535. Now, each of these spaces store a byte, so you want to be able to get the contents and store to each (reading and writing). Since registers can store numbers (a, b, c, d, e, h, and l hold one byte, and bc, de, hl, sp, ix, and iy hold 2 bytes each). Two bytes is exactly what we need to store 16-bit numbers, so let's put the number, hmmm, 42 in hl. That means hl will hold the number 42. In order to actually put 42 in hl, we use a regular load statement:


Code:
ld hl,42


Easy enough. But say we want to save that for later. In ourt theoretical memory, let's decide that we want the 1,338th location to hold our number. Its address is 1337 (because remember that the first location is 0), so we want to store hl into the _address_ 1337. To do that, we can use:


Code:
ld hl,1337
ld (hl),42


Here we have both methods together. First, we are simply loading the number 1337 into hl. Next, we are loading 42 into the address of memory named by hl. This will put the binary equivalent of 42 into address 1337 of memory. If we want it again, we simply do:


Code:
ld hl,(1337)


This gets the contents of 1337 into hl, which is 42, instead of putting the number 1337 into hl. Makes sense?
_________________


Back to top
calc84maniac


Epic z80 roflpwner


Joined: 01 Aug 2006
Posts: 1503
Location: The ex-planet Pluto

Posted: 10 Sep 2006 11:22:32 am    Post subject:

Yes, it somehow does. Smile
_________________
~calc84maniac has spoken.

Projects:
TI-Boy SE
F-Zero
Super Mario (aka Project M)
Back to top
something1990


Supreme Commander of the Asgard Fleet


Joined: 12 Jan 2006
Posts: 1144
Location: Orilla

Posted: 10 Sep 2006 11:55:42 am    Post subject:

It more than "somehow does" make sense. Kerm explained it in an understandable way. I have one question though. You have to load the address to hl and then load the value to that address right? You can't simply do ld (1337) , 42?
_________________
Check the links:



Please help save Stargate SG-1.
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55773
Location: Earth, Sol, Milky Way

Posted: 10 Sep 2006 01:26:17 pm    Post subject:

Only because of limitations of the z80. That's essentially what I'm doing in two instructions.
_________________


Back to top
Ultimate Dev'r


Join us on #cemetech-vaporware


Joined: 16 Mar 2005
Posts: 7297

Posted: 10 Sep 2006 04:13:59 pm    Post subject:

Generally you don't have this problem with microcontrollers Razz
_________________



Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55773
Location: Earth, Sol, Milky Way

Posted: 10 Sep 2006 06:54:42 pm    Post subject:

By the way, here are the C equivalents:


Code:
hl=42;



Code:
hl=1337;
*hl = 42;



Code:
a = 1337;
hl = *a;

_________________


Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.028397 seconds.