Reputation: 13
If a 16 bit value is stored (in a pic microcontroller) as a High byte and Low byte, how do you go about dividing them by 2? How can a 16 bit number be rotated right?
Thanks.
Upvotes: 1
Views: 2457
Reputation: 726849
Dividing a 16-bit number by two is equivalent to shifting the number right by a single bit*. Clear the carry flag, rotate the higher byte right through the carry, and then rotate the lower byte right through the carry. You can find code for it here:
LSR16 MACRO VAR16
BCF STATUS, C ; Clear carry
RRF (VAR16)+1,F ; Rotate high byte right
RRF (VAR16),F ; Rotate low byte right
ENDM
0.5
is truncated.
Upvotes: 7