Shop Learn
Arithmetic shifting a double in PASM2? — Parallax Forums

Arithmetic shifting a double in PASM2?

bob_g4bbybob_g4bby Posts: 311
edited 2022-02-22 10:32 in PASM2/Spin2 (P2)

Hi,

I'm writing a driver in TAQOZ for the MS5611 air pressure sensor and the conversion of raw pressure to real units entails 58 bit precision - says the application guide. Being a newcomer to PASM2, I've written a pair of functions for arithmetic shift left and right of a 64 bit number by n places for the TAQOZ assembler:-

--- arithmetic shift signed double d1 right by n positions, result is d2
code D>>    ( d1 n -- d2 )
.l1
    sar b,#1 wc
    sar c,#1
    djnz a,#l1
    jmp #@DROP
end

--- arithmetic shift signed double d1 left by n positions, result is d2
code D<<    ( d1 n -- d2 )
.l1
    sal c,#1 wc
    sal b,#1
    djnz a,#l1
    jmp #@DROP
end

However, neither is doing what I'd hoped for - can anyone see what I've done wrong or omitted please?

Comments

  • AribaAriba Posts: 2,584

    You need to shift the carry into the second register:

    Shift arithmetic right:

        sar b,#1 wc
        rcr c,#1
    

    Shift left (arithmetic and bitwise is the same):

        shl c,#1 wc
        rcl b,#1
    

    Andy

  • Thank you Andy, those functions work.

Sign In or Register to comment.