Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bit Shifts
#1
C provides bit shift functions >> and << which aren't available in Sinclair or ZX basic. Since I happened to have a need for such a function, I decided to drop them up here. Again, this is something that's easy on the CPU.

They work with Long Unsigned integers - and will work fine with smaller values, or you can use them as a template for 16 or 8 bit versions in assembler.

Code:
FUNCTION bitL(num as uLong) as uLong
  REM we get DEHL as uLong
  asm
   SLA  L
   RL  H
   RL  E
   RL  D
  END asm
END FUNCTION

Code:
FUNCTION bitR(num as uLong) as uLong
  REM we get DEHL as uLong
  asm
   SRA  D
   RES 7,D ; makes a zero shift into D instead of what was there originally. If you want this to work with signed numbers, you could always change it to res 6,d.
   RR  E
   RR  H
   RR  L
  END asm
END FUNCTION
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)