Shop OBEX P1 Docs P2 Docs Learn Events
Adding signed bytes in PASM — Parallax Forums

Adding signed bytes in PASM

CogSaverCogSaver Posts: 17
edited 2013-06-22 15:05 in Propeller 1
I may be over complicating this, but all I need to do is add some signed bytes that are read from hub with rdbyte.

I understand the "adds D,S" command, but for that to work I need to get my signed byte values extended to longs.
I fail to find any "sign extend" command (like the ~ in SPIN) to make a signed long from my signed bytes, and in case this command
does not exist, will it be as simple as copying the most significant bit in the bytevalue into the upper 24 bits if the long ?
(test bit 7 then OR with the upper 24 bits set if negative)


Any help appreciated.
CogSaver

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-06-22 10:28
    You can do it with the right kind of shift left by 24 bits and then shift back by 24 bits which will propagate the top most bit of the byte into the top 24 bits of the long. I leave it as an exercise to find the "right kind" of shitfs.
  • CogSaverCogSaver Posts: 17
    edited 2013-06-22 11:22
    Thanks Heater

    After a quick detour, thinking I had to do this with the help of the C-flag (apparantly any left shift or rotate with the WC effect specified, the C flag is set equal to Value’s original bit 31) I ended up with the following :
           ' Extend signed byte to signed long 
    
                  SHL       value,#24       
                  SAR       value,#24  
    

    CogSaver
  • Heater.Heater. Posts: 21,230
    edited 2013-06-22 15:05
    Yep, looks like what I used to do the 8 bit maths in the ZiCog Z80 emulator.

    The setting of the C flag for shifts isn't what people expect. I think I read that it has been fixed in the Prop II.
Sign In or Register to comment.