Dan1984mor2017 wrote
I have been able to create a little program that will countdown from 10 or any input actual. But my program seems to keep adding the same numbers over and over again. It loops but does not loop the addition part. I'm confused.
So desk check it and see what it does compared to what you want it to do.
It would be really helpful if you where to indicate what the values in the five registers you use are meant to represent.
But regardless, let's look at your final two instructions:
@R0
D=M;JGT
What will these two instructions do? Not what you think you would want them to do, but what will they actually do?
@R0 will load the A register with the value 0.
D=M;JGT will copy the value stored at RAM[0] into the D register and, if that value is strictly greater than 0, it will jump to the instruction whose address is currently stored in the A register (which is 0 due to the prior instruction).
Is this really what you want?
Even if it is, throughout your entire program there ONLY register whose value you EVER change is the value stored in R2. Hence, whatever value is initially stored in R0 will ALWAYS be the value stored in R0 when the last two instructions are reached.
Is this really what you want?
A good first step is to express what you really want to have happen using terms that a second grader could easily follow. For instance, something like:
Set up:
Name the following index cards: A, D, R0, R1
(write those names in pen in the upper right corner of the card).
On Card R0, write the value 6 (in pencil).
On Card R1, write the value 2 (in pencil).
From this point on, whenever you are told to write a value on a card, you will erase whatever value it has there and replace it (in pencil) with the new value.
Run:
Step 0: IF the value written on Card R0 is less than or equal to zero, goto to Step 5
Step 1: On Card D, write the value that is currently written on Card R0.
Step 2: On Card D, write the value obtained by subtracting the value on Card R1 from the value on Card D.
Step 3: On Card R0, write the value currently written on Card D.
Step 4: Go to Step 0:
Step 5: DONE
These steps can each then be converted to a very few lines of assembly code.
But b