RAM not clearing between runs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

RAM not clearing between runs

ngdrummer
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!
Reply | Threaded
Open this post in threaded view
|

Re: RAM not clearing between runs

ngdrummer
Adding to this, the ram locations even stay valued after running further attempts unless I close the emulator and open it again
Reply | Threaded
Open this post in threaded view
|

Re: RAM not clearing between runs

ngdrummer
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.
Reply | Threaded
Open this post in threaded view
|

Re: RAM not clearing between runs

cadet1620
Administrator
In reply to this post by ngdrummer
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
Reply | Threaded
Open this post in threaded view
|

Re: RAM not clearing between runs

ngdrummer
Ah, I see what happened. When I updated the asm, I forgot to update the HACK file, and I visually watched as the asm loaded with the new data, but when pushing the "play" button, the ROM pins changed back to what was in the previous HACK data, so that first line clearing the ADDR information never actually made it to the running program.