Mark Rages wrote: > Here's a design challenge for you guys: > > I have values in three file registers: fileA, fileB, fileC. > > I want to choose the value that's in the middle (numerically) and put it into W. movf fileB,W subwf fileA,W ; W=A-B movf fileB,W ; assume B is larger skpnc ; if Carry is clear then B is larger movf fileA,W ; carry is set, so A is larger (or equal) movwf temp ;temp = max(A,B) subwf fileC,W ; compare C, W = C-max(A,B) movf temp,W ; assume max(A,B) > C skpnc ; movf fileC,W ; C is larger than the max(A,B) ; W = max(A,B,C) If you don't want to use a temp then: movf fileB,W subwf fileA,W ; W=B-A movf fileB,W ; assume B is larger skpnc ; if Carry is clear then B is larger movf fileA,W ; carry is set, so A is larger subwf fileC,W ; compare C skpnc ; movf fileC,W ; C is larger than the max(A,B) skpc subwf fileC,W ; W = C - (C-max(A,B)) = max(A,B) ; W = max(A,B,C) If you can trash the registers, you can write: movf fileB,W subwf fileA,F skpnc movf fileA,W subwf fileC,F skpnc movf fileC,W This is of course untested and probably has bugs... but I believe the approach works okay. Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist