PASM: d,s field specified by negative number causes overflow and produces unexpcted op-code
yisiguro
Posts: 52
Perhaps it is useless to discuss so much but I feel it is not natural behavior.
Code below is valid and does not cause any compile error,
but results
I'm using PropellerTool PropellerIDE. This occurs when d and/or s field is specified by negative number ( decimal or not ).
(edit:)
Thanks for comments. I see this issue is caused with OpenSpin invoked by PropellerIDE.
I read source code of OpenSpin on github repo, and found lines related to this issue.
Actually, I've mistakenly believed that source operand specified by immediate value is sign-extended for some instructions, such as MOV, ADD, etc.
Of course sign is not extended, but filled by zero, I know now.
Code below is valid and does not cause any compile error,
con rate = 115200 obj t:"Parallax Serial Terminal" pub main t.Start(rate) t.Hex(x,8) ' "A0FFFE00" expected t.NewLine t.Hex(y,8) ' "A0FC01FF" expected t.NewLine t.Hex(z,8) ' "A0FC0000" expected t.NewLine repeat dat org 0 x mov -1,#0 y mov 0,#-1 z mov 0,#0
but results
FFFFFE00 FFFFFFFF A0FC0000
I'm using PropellerTool PropellerIDE. This occurs when d and/or s field is specified by negative number ( decimal or not ).
(edit:)
Thanks for comments. I see this issue is caused with OpenSpin invoked by PropellerIDE.
I read source code of OpenSpin on github repo, and found lines related to this issue.
Actually, I've mistakenly believed that source operand specified by immediate value is sign-extended for some instructions, such as MOV, ADD, etc.
Of course sign is not extended, but filled by zero, I know now.
Comments
Sorry, I mistook. I'm using PropellerIDE, not PropellerTool.
(edit)
I was very careless that I did not test this issue on any other pasm compilers:
PropellerTool (1.3.2) : raise error
PropellerIDE (0.33.3) : pass but unexpected output
Propellent (1.6) : raise error
To get the bit pattern of a negative number, complement the bit pattern of the absolute value (all 1's to 0 and all 0's to 1) and then add 1. For example, if you do this with 1, you go from all zeroes except 1 in the lsb, to all 1's except 0 in the lsb, and when you add 1 you get all bits 1 for minus 1.
What you say is exactly what I expected, but what happened is not: that produces wrong instruction "WAITVID" from any instruction.
Anyway, that seems to be a bug of PropellerIDE, and I'll try newer version from github repo.
Thanks.
PropTool is GUI only and has the least features, but is the reference compiler.
OpenSpin has this funky bug and lacks some features (assembler listings, adding a #define from the command line).
BSTC is closed source but has lots of features, but causes strange bugs sometimes.
Fastspin uses a lot of memory.
Homespun, I haven't used yet due to not having found a binary yet (and being too lazy to download a C# compiler).
Does this happen with OpenSpin?
Actually, I guess it is a bug ether way...