Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
USR U{Shift+S} B7 1.0+ Function

USR value )
Parameters Type Legal Value(s) Default Value Note(s)
value Numeric
depends of function definition
Returns Type Value(s) Note(s)
result Floating-point
depends on function definition
Call a machine-language program to evaluate a custom user-function.

The USR function is the functional equivalant to the SYS command/statement.  Another way to think of it, is as the machine-language equivalant of the BASIC (DEF)FN.  In contrast to SYS, you pass a numeric value to be processed, not a memory address (the memory address of the machine-language program is a secret variable).  In contrast to (DEF)FN, the definition is written is assembly/machine language, instead of BASIC.  Also different from (DEF)FN is that you can have only one custom USR function (unless you keep POKE'ing different values, see below).
Because it calls a machine-language program, this function is very non-portable.  If no machine-langauge program has been "set up", then calling USR will generate ILLEGAL QUANTITY ERROR.  To "set up" USR, poke the start address of a machine-language program (which should store its result in BASIC's floating-point accumulator) into the magic addresses shown below:
Machine Address
Low Byte High Byte
PET ??? ???
Commodore 64  785 786 
Commodore 16 1281  1282 
Plus/4  1281  1282 
Commodore 128 4633 4644 
You will get TYPE MISMATCH ERROR with a string value.
Because this is extemely machine-dependent, there are no examples.
  Compare With  
  Contrast With  
  See Also  

© H2Obsession, 2014