@Ashbad, colons may not be necessary, but they increase the readability of your code and help when people are trying to help you with it. Not to mention, it is a nice style and makes your code prettier (which happens to be a big thing with me Razz)

@David, I still don't really like the hEx thing, because it seems like you are doing so much more work than is necessary. But, to the xor a thing. xor REG8 takes an 8 bit register, and xors it with A. So when you do xor a, you are doing this: A = A xor A. If A is 10110010, then you are doing:
Code:
10110010
10110010 XOR
--------
00000000
Does that make sense?
Exclusive Or, yeah it xors a Very Happy

Thanks a lot.
yeah, maybe I should add the colons when I post example code Razz but I personally find the lack of them comforting Smile much like how I adore uppercase.
Uppercase mnemonics make me sad :/ It is difficult to work on code when I keep thinking it is yelling at me.
To set where we place a string we can do:


Code:
ld a, 3
ld (curRow), a
ld a, 2
ld (curCol), a


Can we directly do:


Code:

ld (curRow),3
ld (curCol),2
; It'd be faster this way I guess
ScoutDavid wrote:
I don't like labels, they don't exist in hexadecimal, or at least we don't have to set them.
It doesn't make you cool or manly to try to do things the hardest way possible. Sad I feel like you really are making your life as hard as possible. Sad What reason could you have for not wanting to use labels? @_player: I prefer uppercase mnemonics to no mnemonics. Smile
no, we unfortunately cannot load constants directly into places in memory Sad we have to settle for loading it in a supported 8 bit register first.
KermMartian wrote:
ScoutDavid wrote:
I don't like labels, they don't exist in hexadecimal, or at least we don't have to set them.
It doesn't make you cool or manly to try to do things the hardest way possible. Sad I feel like you really are making your life as hard as possible. Sad What reason could you have for not wanting to use labels? @_player: I prefer uppercase mnemonics to no mnemonics. Smile


Not again.

Thanks Ashbad.

I have a new question!

ld (hl),l

This saves the address of hl in l right? Or does it save what's stored in hl?

I never really got the parentheses thing.
It loads L into the location pointed to by HL.
If the two byte memory addresses are next to eachother in memory you could perform a single 16-bit load to write to both at once. curRow appears before curCol, so you could do this:


Code:
    ld hl,3+(2*256)
    ld (curRow),hl


Remember that the Z80 is little-endian, i.e. the least-significant byte appears at the lower memory address.
it stored l into the address in memory pointed to by HL -- so if HL is equal to 50000, then it loads the value stored into L to the 50000th place in memory Wink
Ashbad wrote:
it stored l into the address in memory pointed to by HL -- so if HL is equal to 50000, then it loads the value stored into L to the 50000th place in memory Wink


I gave a bad example, I meant something like

ld l,(hl)

Does it store the address of hl in l?
Or for a more realistic example: if HL = $1245, ld (hl),l loads 45 into RAM at the location $1245.
Re: your earlier question. David, you have the storage order backwards. ld ($BBBB),a loads register a into memory address $BBBB, while ld a,($BBBB) loads the contents of memory at $BBBB into the accumulator.

Re: your new question: ld l,(hl) retrieves the contents of the memory named in hl, and stores that byte in l.
scout, yes, it stores the byte at the value pointed to by HL into L -- however, I don't know if L is a supported argument.
Ashbad wrote:
scout, yes, it stores the byte at the value pointed to by HL into L -- however, I don't know if L is a supported argument.
Yes, that is valid. For example, the four-byte way to do (infinitely faster) the three-byte opcode bcall(_ldhlind):


Code:
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
Yes, L is a supported argument to ld reg8,(hl). I, too, would like to know why you dislike labels, btw.
Parentheses usually refer to indirection; rather than meaning "the value of X" they mean "the value stored in memory at address X".


Code:
    ld a,5 ; Loads the value 5 into A.
    ld a,(5) ; Loads the value stored in memory address 5 into A.


The one exception to this rule is jp (hl) which (confusingly) jumps to the value of hl; it's effectively ld pc,hl.
Thanks you all I got it. What if I did something like:


Code:
ld a,5

ld l,a
ld l,(a)


Are the last two lines the same thing?

Actually, ld l,(a) doesn't exist Sad But is there something like it?
ld l,(a) would be like:
Code:
 ld h,0
 ld l,a
 ld a,(hl)
  
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
» Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
» View previous topic :: View next topic  
Page 2 of 10
» All times are UTC - 5 Hours
 
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

 

Advertisement