ABS (ROM Routine)
Note: This article describes the ABS numerical routine for calculating the absolute value in BASIC-ROM.
Name: | ABS | ||||||
Description: | Calculate amount of floating point register FAC. | ||||||
Entry point: | $BC58 / 48216 | ||||||
Passed arguments: | |||||||
Return values: | |||||||
Accumulator: | unchanged | ||||||
X-Register: | unchanged | ||||||
Y register: | unchanged | ||||||
Negative flag: | 0 |
The ROM routine ABS[1][2] — sometimes also as FACABS[3] - sets the sign of the number stored in the floating point register FAC to "positive" and thus replaces it with its Absolute Value . Its entry point is stored in the table of BASIC functions at address $A056, so that the routine is called by the BASIC interpreter each time the function ABS is evaluated.
If FAC was less than 0 before calling ABS, ABS simply removes the sign and turns FAC into a positive number, whereby its distance from 0 remains the same. Otherwise, FAC is not changed by calling ABS.
Algorithm[edit | edit source]
ABS consists of just a single machine instruction that shifts the value stored at address 102/$66 one place to the right, thereby changing the sign of FAC (contained in the most significant bit) to "positive " puts. It is therefore advisable not to call the ROM routine ABS to calculate the amount of FAC, but rather the corresponding command
LSR *$66
to be used directly, as this saves both computing time and storage space (5 instead of 17 system clocks, 2 instead of 3 bytes).
ABS is never called directly within the BASIC ROM, but the entry point of this ROM routine is only stored in the table of BASIC functions as an implementation of the BASIC function ABS.
Runtime behavior[edit | edit source]
The running time of ABS is 17 system cycles.
On the Commodore 64, one system clock corresponds to around one microsecond (μs).
Links[edit | edit source]
- Disassembly of ABS/$BC58 on All About Your 64
- CodeBase 64: Floating Point Math
- C64 BASIC & KERNAL ROM Disassembly by Michael Steil
- C64OS: Floating Point Math from BASIC