Programming - Move Commands and other basics

Move Commands and other basics

Time for some commands, which gives you the power to command the commodore to do anything you want it to. The first ones we're going to look at are in the category "move commands", since they can move data. On other platforms you often have a command called move or mov, but on a c64 they're called other things like LDA, STA, etc. The principle of move commands on c64 is that either you move something into a processor register, or you move from a register to a memory address. The registers are called A (accumulator), X and Y. They can each hold a byte, which is a number from 0 to 255, or in hex 00 to FF, or in binary 00000000 to 11111111. Let's have a little example, which you can type in and test like the previous piece of code... (Remember to type .A2000 before the 1st line and all that!)

LDA #$07
STA $D021
BRK

Again, start it with G2000, and the amazing result should be a yellow screen.

Explaination:

LDA #$07 means "load accumulator with the value 7" and moves the number 7 (the color code for yellow) into the accumulator (aka the A register.)

STA $D021 means "store the value of the accumulator into the memory address $D021", which is where the background color is located.

BRK breaks out of the program so you return to the mon. This is necessary because the code doesn't loop forever like in the flicker example.

Instead of LDA #$07 we could also write LDA $07, which would mean that it was the content of the address $0007 we were moving into the accumulator. That's ofcuz a whole another story, so please notice that there's a big difference between LDA value and LDA address. Always remember the number sign (#) when it's a value you wanna LDA! If you try this...

LDA $D021
STA $D020
BRK

... it moves the background color to the border. Or maybe "move" is the wrong word since it doesn't change the source address, it just copies it. As you might have guessed $D020 and $D021 controls the border/background color. Everything that has to do with graphics is controlled by the addresses that start with $D0, but more about that later.

Time to see what we can use the X and Y registers for. Every time we write LDA or STA we could just aswell have used LDX/STX or LDY/STY. That would have resulted in the same effect, the only difference is that it's the X and Y registers that are used instead of A. But these registers can also be used for some more purposes. Let's try this...

LDX #$21
LDA #$0B
STA $D000,X
BRK

This is an example of socalled relative addressing. The first line loads X with the value $21, in the next line A gets the value $00, and in the 3rd line the value of A is moved to the address $D000+X, which means $D021 in this case. (The background color again... I'm really original, huh?)... Y can also be used for realive addressing (STA $1234,Y), and you can also LDA relaive (LDA $1234,X)... The relative addressing modes are very useful in loops, but more about that in the Compare/Branch section.

Another type of move commands is called transfer commands, and they move data within the registers. An example is TXA which means transfer X to A. So if X held the value $DF, A is now $DF. As in other move commands the source (X in this case) is not affected, so they both holds the value $DF now. Here's some more transfer commands is: TXA, TYA, TAX and TAY. They all transfer the 1st register to the 2nd - eg. TAY means A -> Y.

Well, we haven't really covered all of the move commands, but I guess it's time to move on, so it doesn't get too boring...

For any Comments or Questions please contact us.

Back to the TOC