ouverson wrote
I was only counting addresses. Thanks for the confirmation on @23.
Then be sure to remember that addresses start with 0.
How is the C-instruction, M=0 the beginning of the loop?
Because the bottom of the loop jumps to it. That's what defines the top of the loop.
I thought all instructions must start with an A-instruction? Every example thus far has been: A, C, A, C, A, C...A, C
Thank you.
If an instruction "starts" with an A-instruction then it is an A-instruction.
Program code a simply a list of instructions and is whatever mix of A-instructions and C-instructions that are needed to implement the logic needed to perform the task.
In general there is no value in following an A-instruction with another A-instruction since they ONLY thing that an A-instruction does is load a literal value into the A-register. If you then immediately do another A-instruction, then you overwrite the prior A-instruction's result rendering it useless.
It is quite common to have runs of C-instructions, but it is uncommon for them to be very long because usually you need to get a literal value or load a memory address.
Programs usually start with an A-instruction because that is how we normally make it start from a well-defined state. But this is not required.
Consider a program that starts
@SP
Well, all that does is load the value 0 into the A register. This can be accomplished just fine with the C-instruction.
A=0
instead.