I have added comments to each line... > From: Andrew Warren > > John Payson wrote: > > > How about this one [figure out what it does yourself :-)] > > > > movf Num1,w w = n1 > > movwf Result r = n1 > > > > movf Num2,w w = n2 > > subwf Result,w w = n1 - n2 > > btfss C > > subwf Result,f if (n2 > n1) r = n1 - (n1 - n2) = n2 > > > > movf Num3,w w = n3 > > subwf Result,w r = r - n3 = max(n1,n2) - n3 > > btfss C > > subwf Result,f if (n3 > max(n1,n2)) r = n3 thus result = max((unsigned chars) n1, n2, n3) > > > > Anyone know of any smaller way? > > John: > > Does this work? > > MOVF NUM1,W w = n1 > SUBWF NUM2,W w = n2 - n1 > > MOVF NUM1,W w = n1 > SKPC > MOVF NUM2,W if (n1 > n2) w = n2 > > MOVWF RESULT r = min(n2, n1) > > SUBWF NUM3,W w = n3 - min(n2, n1) > SKPC > ADDWF RESULT if (min(n2,n1) > n3) r = min(n2,n1) + n3 - min(n2,n1) = n3 thus result = min(n1, n2, n3). Not exactly the same, Andy, but we assume you meant SKPNC instead of SKPC. I know I forget this wierd Microchip convention all the time -- I'm so used to carry meaning the answer was negative after a subtraction. This is reminiscent of the XOR technique of swapping 2 or more bytes. It basically works because there are operations (op) such that given Z = X op Y, then if you know any two of X, Y or Z, then the third value can be reconstructed. ADD, SUB and XOR are such op's. AND and OR, on the other hand, fundamentally destroy information. Regards, SJH Canberra, Australia PS: I missed your subsequent post with 'the answer' so forgive me if I'm correcting an already corrected oversight.