Administrator
|
This post was updated on .
How should I know? I don't even know what that long list of instructions is supposed to accomplish. In your first post you talked about b to the power of a. Is this related to that? If so, your code references x and y. Is it x to the y or y to the x? Or is this multiplying x and y? What? I'm not a mind reader.
But just looking at your first three blocks of code I don't think it is doing what you want it to, whatever that happens to be.
@R0
D=M
@x
M=D //R0 = x
The comment "R0 = x" implies that you are trying to change the value stored in R0 and set it equal to the value in the variable x. But you are doing just the opposite (which is what I suspect you actually want). You really should use the normal convention that the value on the left of the assignment operator is the target of the operation. So the comment should be "x = R0". Similarly, the comment in the block below should be "y = R1".
@R1
D=M
@y
M=D //R1 = y
Now you use the normal convention for the comment "D=insum". At the very least, you need to be consistent.
@insum
D=M //D=insum
@x
M=D //insum = x
So does "insum = x" mean you want to change the value stored in insum, or the value stored in x? Since your comments have gone both ways, it's impossible to know. Again, I'm not a mind reader.
But if you want to change the value in insum, wouldn't the address of insum need to be in the A register? If your code is correct, then you are wanting to change the value in the variable x. But if so, then what was the point of the first block of code?
If you had tested your code after writing these three block of code and checking to see if the values stored in the various memory locations were what you wanted them to be, you could have found and fixed this issue before proceeding to write a bunch of code that was pretty much guaranteed to never work.
Again -- small steps, incremental development, and frequent testing are the keys to success.
|