PASM: d,s field specified by negative number causes overflow and produces unexpcted op-code
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.
$ cat main.spin 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
BSTC, HomeSpun and FastSpin complain about the operands:$ bstc -L /opt/parallax.spin.src/spin main.spin Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved Compiled for i386 Linux at 08:17:46 on 2009/07/20 Loading Object main Loading Object Parallax Serial Terminal main(17,7) Error : Parameter exceeds $1FF mov -1,#0 ______^ Compiled 285 Lines of Code in 0.009 Seconds
$ fastspin -L /opt/parallax.spin.src/spin main.spin Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc. Version 3.9.24 Compiled on: Mar 24 2019 main.spin |-Parallax Serial Terminal.spin main.spin(17) error: Destination operand too big for mov main.spin(19) error: Source operand too big for mov
$ homespun -L /opt/parallax.spin.src/spin main.spin Homespun Spin Compiler 0.32 - Batang Build parsing main.spin parsing /opt/parallax.spin.src/spin/Parallax Serial Terminal.spin compiling main.spin Error: main.spin (17, 8): Destination register cannot exceed $1ff mov -1,#0 ^
OpenSpin does not.$ openspin -L /opt/parallax.spin.src/spin main.spin Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2018 Parallax Inc. DBA Parallax Semiconductor. Version 1.00.81 Compiled on Dec 18 2018 13:23:20 Compiling... main.spin |-Parallax Serial Terminal.spin Done. Program size is 1176 bytes
Maybe OpenSpin just should complain about this like the others already do?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...