From C64-Wiki
Jump to navigationJump to search

Note: This article describes the STRVAL numeric routine for converting strings to floating point numbers in BASIC-ROM.

Description: Convert ASCII string to floating point number in floating point register FAC.
Entry point: $B7B5 / 47029
Passed arguments:
Accumulator: Length of the string to be read
Other: Address 34/$22 (Low-Byte) / 35/$23 (High-Byte) = Pointer to numeric string to be read
Return values:
Other: FAC = read number

STRVAL — sometimes also referred to as STRFAC[1] — reads a numeric ASCII string and converts it into a floating point number, which is then stored in the Floating point register FAC. When the routine is called, the start address of this string is passed to addresses 34/$22 (Low-Byte) and 35/$23 (High-Byte); The length of the string must be stored in the accumulator. The entry point of STRVAL is in the beginning area of the ROM routine, which is stored as an implementation of the function VAL in the table of BASIC functions at address $A074.

Calling STRVAL overwrites the floating point range at addresses 93/$5D to 103/$67 and also changes the auxiliary pointers at addresses 34/$22 to 35/$23 and 133/$71 to 114/$72.

Algorithm[edit | edit source]

STRVAL does not implement an independent conversion, but initially only saves the read pointer of the routine CHRGET to the addresses 133/$71 to 114/$72. STRVAL then replaces this pointer with the address of the string to be converted, briefly terminates the string with a null byte and then calls the ROM routine FIN, which carries out the actual conversion. After that, STRVAL resets the CHRGET pointer to its original value and also restores the character after the string that was overwritten by null termination.

Runtime behavior[edit | edit source]

The runtime of STRVAL consists of the runtime of the ROM routine FIN and the computing time for the preparation and follow-up of its call. The latter takes between 124 and 125 system cycles.

On the Commodore 64, one system clock corresponds to around one microsecond (μs).

Links[edit | edit source]

References[edit | edit source]