Shop OBEX P1 Docs P2 Docs Learn Events
Shift instructions — Parallax Forums

Shift instructions

NefastorNefastor Posts: 14
edited 2007-01-03 22:19 in Propeller 1
Hi all,

I'm using shifts (SHL, SHR) and I am wondering this : suppose I shift left, are the LSB's cleared or set ? (resp, if I shift right, are the MSB's cleared or set ?)

The chip's manual does not indicate this (page 402)

I assume the bits are cleared, since this is the most sensible behavior : SHL can then be used to multiply by powers of 2.

Still, I'd prefer to be sure smilewinkgrin.gif

Jean

Comments

  • asterickasterick Posts: 158
    edited 2007-01-03 20:10
    If it's a logical shift, than the MSB's are copied from the previous MSB.

    otherwise, 0's are shifted in.
  • NefastorNefastor Posts: 14
    edited 2007-01-03 22:04
    asterick said...
    If it's a logical shift, than the MSB's are copied from the previous MSB.

    otherwise, 0's are shifted in.

    Not sure you got this right : a shift where the MSB is copied from the previous MSB would be a right arithmetic shift, not a right logical shift : keeping the MSB preserves the sign bit.

    My question still stands.

    Jean
  • rokickirokicki Posts: 1,000
    edited 2007-01-03 22:05
    LSBs are cleared on left shifts. On logical shift rights, MSBs are cleared. On arithmetic shift rights, MSBs are copied.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-03 22:11
    All shift routines will shift in a 0, except arithmetic shift right which shifts the MSB in.

    Mathmatically its:
    shl = multiply by two
    shr = divide by two unsigned
    sar = divide by two signed

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 1/3/2007 10:19:36 PM GMT
  • asterickasterick Posts: 158
    edited 2007-01-03 22:18
    Yea, I had it backwards.
  • rokickirokicki Posts: 1,000
    edited 2007-01-03 22:19
    The tricky case is the extended rotates. These copy the carry bit to *all* "inshifted" positions, rather than
    doing an extended (33-bit) "rotate".
Sign In or Register to comment.