Woohoo! I'm happy that finally looking through all that code is over with, and now we can really go in depth.
So, about the title...you may have noticed that at the beginning of the code, I jumped with jp main. Everywhere else, though, I jumped with jr. What's the difference between them, anyway?
Well, it actually has to do with spacing. You see, if a point in memory is 128 bytes forward or behind the point in code you're in, then you can use jr. If it's further away, then you have to use jp.
The reason for this is because jp is jump, and jr is jump relative. While jp uses two bytes for the location (which can contain values up to 65535,) jr is smaller, and only uses one byte (up to 255). So that's out of the way...
What about call, though? Oh, wait, I didn't even tell you about call, did I? It's sort of a modified version of jp. You see, just like a higher language such as C, z80 assembly can have functions. The standard function would go like this.
Name:
; code
ret
Name is the label, so you'd call the function using call Name. The code goes in the middle, and ret is what signals that the function is over. There's no call relative, although if there were one it wouldn't be very useful.
So that's all you really need to know about jr's, jp's, and calls. That's not all I wanted to cover, though. Another concept I wanted to get out of the way, is numbers.
Did you notice that I kept saying $0404 and %01010101? What do these mean? Well, they're actually WLA syntax. You see, putting $ before a number makes it hexadecimal. Hex is basically the counting system that goes 0-9,a-f,10-19,1a-1f, and so on.
The percentage symbol makes binary. Binary is what computers run off of on the lowest of levels, and can only contain two values per bit: 1 and 0. A bit is the smallest piece of memory in existence, and there's 8 bits in a byte. That's why when you usually see binary, it's in sets of 8.
That's pretty much everything I wanted to get done in this little lesson. Next time we'll be covering...I don't know.
No comments:
Post a Comment