Suppose you have this simple C snippet: char c0, c1; void some_function(void) { if(c0>c1) c0_gt_c1(); else c0_lte_c1(); } What is the fastest implementation in assembly (on a mid-range pic)? Note, a simple subtract is inadequate - this is a *signed* comparison. (try for example, c0=-1, c1=1. a -1 is encoded as 0xff. 0xff is greater than 1 when doing a signed comparison. ) Here's an implementation guaranteed to be one of the worst: movf c0,w subwf c1,w btfss c1,7 goto c1_pos c1_neg: btfss c0,7 goto c0_gt_c1 ;; both negative skpnc goto c0_lte_c1 goto c0_gt_c1 c1_pos btfsc c0,7 goto c0_lte_c1 skpnc goto c0_lte_c1 goto c0_gt_c1 14 hideous instructions. (and ~11 cycles worst case execution). Here's something better, but still pretty bad. movf c0,w addlw 0x80 ; Convert from signed to unsigned movwf temp movf c1,w addlw 0x80 ;; now do an unsigned comparison subwf temp ; c1 - c0 skpnc goto c0_lte_c1 goto c0_gt_c1 Can anyone improve this? Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu