Common Assembler Bugs - rosco-pc/propeller-wiki GitHub Wiki
My Assembler Routine Is Doing Something Weird! What's Wrong?
We've all been there. You've got an assembler routine; in an earlier version it worked perfectly, but now it's doing something really weird. You're read it through over and over, and it looks fine. But still it does something weird. And debugging facilities on the Propeller are non-existent. What on earth is wrong?
Here's a check list for things to do. Do them in order, DON'T skip to the end.
- Leave it and go do something else. Go make yourself a tea or a coffee. Go for a walk. Sleep on it. It's amazing how often once you stop staring at the screen it occurs to you why it might not be working. Or at least you think of a good way of narrowing down where the defect is.
- Go through your code checking every single CALL, JMP, JMPRET and DJNZ to make sure that the label that follows has a # in front of it. It's an extremely rare situation when you want a jump of call that isn't immediate. And on the very rare case you do, you should comment it well.
- Go through your code checking that every single CMP or TEST is followed by WC and/or WZ. The only point of these instructions is to set a flag, but they won't do so unless you explicitly say so. Also, if you are doing signed comparisons, make sure you use CMPS.
- Go through your code checking every instance of self modifying code. For immediate effect there must always be at least one instruction separating the point at which the instruction is modified and the instruction that has been modified. Rearrange the code or use a NOP to fix.
- Check that you have not placed a read only special purpose register in the destination field of an instruction unless you really mean it (e.g. CMP CNT,reg). Specifically when using PHSX, read-modify-write will use the shadow register as source but affects both shadow and counter registers during write-back.
- Check that all your RES lines are at the end of your assembler DAT section. After all LONG, WORD and BYTE declarations.
- Try the Propeller Assembler Source-code Debugger. It IS possible to single step though your code and examine data as you do so.
- If you are still stuck, then ask on one of the propeller forums for someone else to take a look. Don't copy more than half a dozen lines into the message itself - the forum software doesn't tend to preserve the formatting at all well. Explain your problem as best you can, and describe what you have already tried, and attach a complete SPIN file or a zip containing the entire project to the post. Anything less is asking for help whilst at the same time ensuring that your helpers will have one hand tied behind their backs. Usually people are very keen to help, but it's unfair to make finding the problem even harder for them than it was for you by not giving them compilable source.