Saturday, 12 April 2008

Sign v2

Shortly after publishing a five line snippet to return the sign of the input value, Roy van Rijn commented with the following improvement.

As with the original, Roy's code calculates the sign of location's b-field, returning -1, 0 or 1.

sign      jmz.b  done,           location
div #1+CORESIZE/2, location
mul.ab #-2, location
nop >location

No comments: