PASM sign extend (+ a few other questions)?
Microcontrolled
Posts: 2,461
I've written a fairly long PASM code that reads through a bytecode script and executes routines according to the script. For several of routines it needs to read a portion of the script as a 9-bit 2's compliment signed integer. Though it reads the integer correctly if it is positive, if a negative number is given (for example %111110110) it will read it as a positive number because the size of the register extends it to %000000000000000000000000111110110 and doesn't see it as negative. I cannot think of an efficient way to "sign extend" the register to read it as a negative, without using the "neg" command which will change the intended integer.
Also, there is another part of the code that only works when I change a portion of SPIN code running in another cog, completely unrelated to this PASM code entirely, from "variable++" to "variable +=2". Though this variable is linked to the PASM script, the portion of SPIN code it is in is bypassed and not even run. I'll post the code if needed, but it's not very neat and I haven't finished commenting it yet. Plus, the fact this function isn't even used yet still affects the code makes me think it doesn't have to do with the PASM code itself.
And one more question, since I am a bit of a n00b to PASM specifically, when you shift bits, do they get shifted into the next (or previous) corresponding register, or are they just removed?
Thanks
Also, there is another part of the code that only works when I change a portion of SPIN code running in another cog, completely unrelated to this PASM code entirely, from "variable++" to "variable +=2". Though this variable is linked to the PASM script, the portion of SPIN code it is in is bypassed and not even run. I'll post the code if needed, but it's not very neat and I haven't finished commenting it yet. Plus, the fact this function isn't even used yet still affects the code makes me think it doesn't have to do with the PASM code itself.
And one more question, since I am a bit of a n00b to PASM specifically, when you shift bits, do they get shifted into the next (or previous) corresponding register, or are they just removed?
Thanks
Comments
A shift instruction will put the first bit in the carry bit if you specify WC, and throw away all the other bits that are shifted out.
The ++ operator does the same function as +=1. If you want to do +=2 you would need to execute ++ twice. So if your code is only doing it once that might be the problem. If your code is doing ++ twice, then you may have a problem with scribbling into memory. This can be cause by using a bad pointer, or a stack that is too small.
(Hopefully I've not made any mistakes, but I'd double check just in case)
outputs 6, while
outputs 5. But
will output 6.
-Phil
Microcontrolled, please post your code.
LC3.spin
True, we don't know whether it was being used in an expression; but regardless, in the general case x++ is still not the same as x += 1, whereas ++x is.
-Phil
You've got:
I think you mean:
-Phil
EDIT: I'm confused by the first few instructions in your PASM code. Shouldn't the PC be set to the value of PAR instead of the contents of the long pointer to by PAR. That is, the PC should be @fal, and not long[@fal] correct?
The existence of this extra long determines whether the branch in your test program is taken or not. This is down to a faulty condition check in the branch subroutine. At this point DR (holding the exec condition) is already destroyed (*2+base) IOW the outcome is highly code position dependent. May I suggest (this also applies to the remaining parameters):