Shop OBEX P1 Docs P2 Docs Learn Events
Nibble-swap Pasm2 code — Parallax Forums

Nibble-swap Pasm2 code

evanhevanh Posts: 15,380
edited 2024-07-13 14:16 in PASM2/Spin2 (P2)

Has anyone got a smaller solution than this for performing a nibble swap?: $12345678 -> $21436587

        splitb  val
        splitw  val
        movbyts val, #%01_00_11_10
        mergew  val
        mergeb  val

Comments

  • Wuerfel_21Wuerfel_21 Posts: 4,664
    edited 2024-07-13 15:06

    split/merge instructions are circular (5x mergew will bring you back to the same value you started with. splitw moves in the opposite direction. splitb/mergeb are just 2x splitw/mergew), so perhaps

            mergeb  val
            movbyts val, #%%1032
            splitb  val
    

    Not tested, may be nonsense Yep, works.

  • evanhevanh Posts: 15,380

    Damn! That's cool! Thanks.

Sign In or Register to comment.