Skip to navigation

Revs on the BBC Micro

Maths (Arithmetic): Absolute16Bit

Name: Absolute16Bit [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Calculate the absolute value (modulus) of a 16-bit number
This routine sets (A T) = |A T|. It can also return (A T) * abs(n), where A is given the sign of n. Arguments: (A T) The number to make positive N flag Controls the sign to be applied: * If we want to calculate |A T|, do an LDA or equivalent before calling the routine * If we want to calculate (A T) * abs(n), do a BIT n before calling the routine * If we want to set the sign of (A T), then call with: * N flag clear to calculate (A T) * 1 * N flag set to calculate (A T) * -1
.Absolute16Bit BPL ScanKeyboard-1 \ If the high byte in A is already positive, return from \ the subroutine (as ScanKeyboard-1 contains an RTS) \ Otherwise fall through into Negate16Bit to negate the \ number in (A T), which will make it positive, so this \ sets (A T) = |A T|