Home > CBM > BASIC > Keywords > Usr
180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Val, Verify, Vol, Wait, While, Width, Window, Xor

KeywordAbbreviationToken (hex)Version(s)Classification
USRU{Shift+S}B71.0+Function

  Syntax  
USR ( value )

ParametersTypeLegal Value(s)Default ValueNote(s)
valueNumeric
depends of function definition

ReturnsTypeValue(s)Note(s)
resultFloating-point
depends on function definition

  Purpose  
Call a machine-language program to evaluate a custom user-function.

  Remarks  
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:

MachineAddress
Low ByteHigh Byte
PET12
CBM-II3 4 
VIC-20 1 2 
Commodore 64 785786 
Commodore 161281 1282 
Plus/4 1281 1282 
Commodore 12846334644 

You will get TYPE MISMATCH ERROR with a string value.

Because this is extemely machine-dependent, there are no examples.


  Compare With  
FN, FETCH, PEEK, RREG, SWAP

  Contrast With  
DEF, DIM, LET

  See Also  
POINTER, POKE, SYS, Variable Format


© H2Obsession, 2014