Why is using ina as a destination register not flagged as a compiler error?
epmoyer
Posts: 314
If you read the Propeller manual carefully (and it's easy to miss) you'll find that ina cannot be used as a destination register in assembly language. That sounds kind of obvious, but consider the instruction:
test ina, MY_BITMASK wc
(which I'm guessing the assembler actually turns into the synonymous "and ina, MY_BITMASK wc,nr")
even though ina is used as a destination register neither of those instructions actually attempt to write ina, and both appear to be perfectly plausible. I haven't tested the "and", but I found that the "test" instruction compiles fine, but does not execute as desired. I beat my head against the wall for almost an hour on this one before I realized my mistake. Once you understand the restriction on ina you can just use "test MY_BITMASK, ina wc" instead (which is equivalent), but I can't help but feel the compiler should have warned me about this one.
test ina, MY_BITMASK wc
(which I'm guessing the assembler actually turns into the synonymous "and ina, MY_BITMASK wc,nr")
even though ina is used as a destination register neither of those instructions actually attempt to write ina, and both appear to be perfectly plausible. I haven't tested the "and", but I found that the "test" instruction compiles fine, but does not execute as desired. I beat my head against the wall for almost an hour on this one before I realized my mistake. Once you understand the restriction on ina you can just use "test MY_BITMASK, ina wc" instead (which is equivalent), but I can't help but feel the compiler should have warned me about this one.
Comments
ina
inb
cnt
phsa
phsb
The matter is not so much that it is "read-only" (which is not the case with PHSx) but that it is: "someone else writes to it, too"
The Tricks and Traps covers this gotcha in situations it's not fully apparent such as test and wr(long/word/byte) (which is a little more of a gotcha since you cant just flip the registers, to write the contents of ina to hub memory you must first copy it's value)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 8/24/2007 8:24:53 PM GMT
<Edit> correction it should be INA_SHADOW = $1F2 </Edit>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 8/24/2007 9:28:01 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I also learnt by this program that it is not allowed to use NR with RDLONG; what a shame! I just needed WZ
Post Edited (deSilva) : 8/24/2007 11:54:31 PM GMT
I spent many hours trying to debug an issue caused by using ina as the destination register for the test instruction. Since I am a new Propeller user, I assumed that my problem was the result of any number of other possible novice mistakes, and so troubleshooting was very difficult. This has really soured my initial impression of the chip, and I am somewhat paranoid that I'll need to read the full 399-page manual in its entirety to avoid stumbling on other unknown caveats. This frustration could be easily prevented for future users by either having the compiler generate a warning, or by adding a note in the manual for the test instruction.
Welcome to the forum.
I do feel you pain. Such little "gotchas" can waste a lot of time. Still all devices have them in my experience. Eventually you find the reason buried in a foot note on page 700 of a two thousand page manual:)
Also my experience is that the Prop instruction set and assembly language are about the simplest, most regular and easy to use of any device I have come across. There are few "gotchas"
Anyway, if you get stuck again, just ask here. There is always someone about to help.
The single most common gotcha I've hit is forgetting # for small integer constants in the source field, especially when using $ hex notation (the lack
is less visible then). In BST at least there's no warning for that, and the symptoms are again weird and wonderful.