Sorry... I guess the list-server doesn't like to see periods at the start of a line. Here's the second try: Alan G. Smith wrote: > Andy said in response to John: > > Does this work? > > > > MOVF NUM1,W > > SUBWF NUM2,W > > MOVF NUM1,W > ... > > Perhaps I just don't understand. But wouldn't the third instruction > destroy all of the work of the first two? Alan: Glad you asked. Here... I'll explain. First, though, a warning: IF YOU WANT TO FIGURE OUT ON YOUR OWN WHAT JOHN PAYSON'S CODE DOES, PLEASE READ NO FURTHER. The rest of you can scroll down. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Sorry, but I didn't want to ruin it for anyone. Ok... Given three values stored in registers NUM1, NUM2, and NUM3, the routine finds the minimum value and stores it in RESULT, leaving NUM1-3 unchanged. Here's the commented version of my code; this should make it clear: ;NOTE: In the comments below, "min(A,B)" means "the lesser of A ; and B". MOVF NUM1,W ;Set the Carry flag if NUM1 is less than SUBWF NUM2,W ;NUM2. MOVF NUM1,W ;Assume that NUM1 was less than NUM2. This ;instruction does NOT affect the Carry flag. SKPC ;If NUM1 really was less than NUM2, skip ;ahead with W = NUM1. MOVF NUM2,W ;Otherwise, W = NUM2. ;At this point, W contains min(NUM1,NUM2). MOVWF RESULT ;Store it in RESULT. ;At this point, both W and RESULT contain min(NUM1,NUM2). SUBWF NUM3,W ;Set the Carry flag if W [which contains ;min(NUM1,NUM2), remember] is less then NUM3. ;At this point, RESULT still holds min(NUM1,NUM2), but W now ;contains NUM3 - min(NUM1,NUM2). SKPC ;If W really was less than NUM3, skip ahead. ADDWF RESULT ;Otherwise, ;RESULT = RESULT + W ; = min(N1,N2) + W ; = min(N1,N2) + [NUM3 - min(N1,N2)] ; = NUM3. ; ;Note that I typed "min(N1,N2)" instead of ;"min(NUM1,NUM2)". Sorry... I ran out of ;space and had to do that to keep the ;formatting ;pretty. ;At this point, RESULT holds min(NUM3,min(NUM1,NUM2)), which is ;of course equivalent to min(NUM1,NUM2,NUM3). Did that help? -Andy P.S. I hope this also explains why I said in an earlier message that assembly-language programmers need to understand the basic arithmetic axioms of association, commutation, and distribution. === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering, Vista, California === http://www.geocities.com/SiliconValley/2499