CopyBits. Copies bits from one register to another with bitmask.

Started by flosigud, Apr 07, 2023, 01:36 PM

Previous topic - Next topic

flosigud

This is just the an assembler trick that many of us remember from early assembler days.You select which bits to copy with a bitmask.


Symbol C = STATUS.0  ' Carry/Borrow bit

Dim source As Byte
' GoTo OverSubs
'$define CopyBits(bitmask,from_file,to_file) '
' Movf from_file,w '
' Xorwf to_file,w '
' Andlw bitmask '
' Xorwf to_file,f

$define CopyBits(bitmask,from_file,to_file) '
WREG = to_file ^ from_file '
WREG = WREG & bitmask '
to_file = to_file ^ WREG


' Copy first three bits


Symbol Bit_mask=%00000111

 
CopyBits(Bit_mask,bTmp1,bTmp2)