View Full Version : Assembly code questioon.
03-24-2009, 09:59 AM
I spent some time debugging assembly code.
I ran into a bug I hadn't seen before, that took me way too long to find.
If I use the following code:
It assembles fine, but doesn't store 'cnt' in _addr.
If I change it like this:
It now works fine.
Has anyone run across this before?
On p. 397 of the manual, it says that read-only registers can only be used in the 'source' field, which this is.
Am I missing something?
Thanks for the help.
03-24-2009, 10:29 AM
In "wrlong cnt,_addr", cnt is in the "destination" field (i.e., bits 17-9 of the instruction). "Source" and "destination" in this context do not necessarily refer to the direction of data movement.
03-24-2009, 10:34 AM
Thanks! Great answer. You're absolutely right!
Too bad the assembler doesn't catch it...
03-24-2009, 10:40 AM
How would it catch it? The assembler has no idea if an address or data is in any particular register.
Paul Baker (mailto:firstname.lastname@example.org)
03-24-2009, 10:47 AM
Another reason to not prohibit it is that there are memory locations "underneath" the hardware read-only registers. If you use one of these locations in the destination field of an instruction, you are accessing the underlying memory location which can occasionally be used to store data or instructions.
03-24-2009, 01:53 PM
do you say that with
mov cnt, # some value
wrlong cnt, addr
you really find 'some value' in HUB RAM? And this works with other special registers as well. Nice to know if that works because it can safe some longs in PASM.
So, what about
mov cnt, cnt
wrlong cnt, addr
then you don't have to waste an additional register.
03-24-2009, 08:58 PM
Considering the time I spent trying to find the 'bug', it seems like there should be a better way.
I'm surprised the assembler has no knowledge of the props special registers. It seems like it would be helpful if it did.
Since it executed without an error, does anyone know which data was actually written to the output address?
It seems like it would make more sense to provide another way to get at the "registers under the registers".
All-in-all, I learned a lot from this little post.
03-24-2009, 09:28 PM
The "shadow RAM" trick only works with read-only registers. One of the video drivers that Chip wrote uses this technique to squeeze out a couple of extra locations. There have been a couple of other uses of these locations for instructions since the hardware fetches instructions from RAM, not the hardware registers.