Normally, you would use the following to increment a variable:
But if hl is not tied up and all you do is check flags, use indirection:
Code: Select all
ld hl,var
inc (hl)
ld a,(hl) ;Optional
@AndySoft: I think you were confusing immediate numbers and addresses... well, here is how
I keep it straight:
Code: Select all
ld hl,$5647 ;loads $56 -> h and $47 into l
Code: Select all
ld hl,86*256+71 ;also loads $56 -> h and $47 into l
Straight and simple. But lets say you want to store 0 -> (penCol) and 56 -> (penRow) with a 16-bit register; what I do is "reverse" them by imagining an X was drawn. So, by drawing the 'X', penCol should be first in the formula:
Code: Select all
ld hl,56*256+0 ;56 comes first
\ /
\ /
X
/ \
V V
ld (penCol),hl
It would also be handy to remember that
penCol comes before
penRow and
curRow comes before
curCol. Hope this helps anyone who gets confused