ngdrummer wrote
Hey there,
So I'm running my mult.asm, and whenever I run it with the script, I always fail on line 4, because I notice the RAM locations don't clear each time (when I assign outside variables to increment within the code), and so for line 4 instead of 8 I have 11, because the previous answer was 3 and the 3 does not erase, but the incrementing RAM location adds the proper amount (8) but just adds it to whatever previous value was in the location.
I even tried adding this into the first 2 lines of code:
@ADDR
M=0 //clear whatever is in ADDR before starting loop
but it still doesn't seem to work
Any help is appreciated, thanks!
Edit: I changed my code to just do the incremental adding straight into R2 and avoid using an added variable, and the code works fine. I guess it must be a problem with the emulator not clearing random variables between runs.
You are correct that RAM doesn't automatically get cleared to 0, but this is not a bug in the emulator.
You must explicitly initialize all variables that you use. This reflects the way real hardware works; RAM powers up with unknown values.
My guess is that your version that was using variables to accumulate the product had a problem in the code that copied the result to R2 after computing the product.
--Mark