Saturday 8 March 2008

Absolute Value

This two-line redcode snippet returns the absolute value of location's b-field.
abs       slt.b  location,       #1+CORESIZE/2
mul.ab #-1, location

2 comments:

Roy van Rijn said...

Also possible without using CORESIZE :-)

mov.b location, #0
sub.b -1,location
sub.b -2,location

(but is longer and slower)

Ryan Duran said...

Inteeresting thoughts