Wishing a C implementation of the assembly SWAPF instruction.
Useful when dealing with BCD values. For instance, to get the high nibble (= The 4 MSB bits of a byte), in assembly, you'd write:
Code: Select all
swapf my_value, w ; Swap the nibbles of "my_value", and store the result to W
andlw 0x0F ; Filter out only what was the high nibble (which is now the lower one)
movwf my_high_nibble Store the result back in a new zone
In miKroC, i had to write:
my_high_nibble = (my_value >> 4)
which was compiled in
Code: Select all
;mikroCeval.c,114 :: my_high_nibble = (my_value >> 4) ;
$003B $0828 MOVF _my_value, 0
$003C $00A7 MOVWF _my_high_nibble
$003D $0CA7 RRF _my_high_nibble, 1
$003E $13A7 BCF _my_high_nibble, 7
$003F $0CA7 RRF _my_high_nibble, 1
$0040 $13A7 BCF _my_high_nibble, 7
$0041 $0CA7 RRF _my_high_nibble, 1
$0042 $13A7 BCF _my_high_nibble, 7
$0043 $0CA7 RRF _my_high_nibble, 1
$0044 $13A7 BCF _my_high_nibble, 7
That is 10 ROM locations and 10 instruction cycles.
Far from being optimized, despite the level 5 optimizations selected in the options.
So, here's my wish : In the BCD library, it would be useful to implement such a swap function, on the byte level.