PASM Question re: SUB
mynet43
Posts: 644
I'm trying to subtract two unsigned numbers and end up with the absolute value of the difference.
I've never tried it before, so I thought it might be faster to just ask [noparse]:)[/noparse]
Here's an example:
mov t1,#1 ' put a 1 in t1
mov t2,#2 ' put a 2 in t2
sub t1,t2 ' subtract t2 from t1 (i.e. 1 - 2 = ?)
The description says if WC is specified, then the C flag is set if the subtraction results in an unsigned borrow. Not sure exactly how to interpret this without printing out some test cases. Not too easy from assembly code.
Would someone please show me how to correct this, so that it always ends up with the absolute value?
Thanks for the help.
Jim
I've never tried it before, so I thought it might be faster to just ask [noparse]:)[/noparse]
Here's an example:
mov t1,#1 ' put a 1 in t1
mov t2,#2 ' put a 2 in t2
sub t1,t2 ' subtract t2 from t1 (i.e. 1 - 2 = ?)
The description says if WC is specified, then the C flag is set if the subtraction results in an unsigned borrow. Not sure exactly how to interpret this without printing out some test cases. Not too easy from assembly code.
Would someone please show me how to correct this, so that it always ends up with the absolute value?
Thanks for the help.
Jim
Comments
-Phil
That looks great!
I was pretty sure it was something like that.
I don't see how it could be any better.
Jim