Example:
* = $1000
ldx #$00 ; Put a 0 the X register – X=0
loop
lda message,x ; Increment the x register by 1 value
sta $0400,x ; Store X into memory location $0400
As we continue to progress, we now arrive at the new instruction that shows sta $0400,x. If you recall our earlier example when STA (Store Accumulator in Memory) was used in Part 3, you may remember that this command will store the contents of the value previously in the accumulator in the parameter listed after STA. This time the sta $0400, x reads as “Store $0400 into the X Register”. It is actually pretty identical to the earlier lda message,x in some aspect. While the earlier instruction reads a series of bytes occupied by the memory space holder pointing to “message”, the sta $0400,x will take the bytes that were loaded from the message area and transfer them into memory starting at $0400. So in Basic this would look like POKE 1024 + x, message. Normally in Basic we would utilize a READ command to grab a stack of bytes (data as it is referred to). In machine language however, we are pulling these from memory locations where they will be stored soon.
Our train of a program is ready to add a new boxcar. Let’s watch the program blossom further.
Example:
* = $1000
ldx #$00 ; Put a 0 the X register – X=0
loop
lda message,x ; Increment the x register by 1 value
sta $0400,x ; Store X into memory location $0400
inx ; Increment the X Register by 1
Okay since we reviewed how INX works in our sample program, I feel safe enough to introduce the next instruction. Just recall that INX increases the X register by one that was previously placed in the accumulator. The next instruction is presented below.
Example:
* = $1000
ldx #$00 ; Put a 0 the X register – X=0
loop
lda message,x ; Increment the x register by 1 value
sta $0400,x ; Store X into memory location $0400
inx ; Increment the X Register by 1
cpx #$c ; Compare the X Register with the immediate value