Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (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
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
SYSS{Shift+Y}9E1.0+Command and Statement

 
Syntax 
SYS address [ , registerA [ , registerX [ , registerY [ , registerP ] ] ] ]
 
ParametersTypeLegal Value(s)Default ValueNote(s)
addressUnsigned integer
0 to 65535
 
Start of machine-language program.
registerAUnsigned byte
0 to 255
0
Only in BASIC 7.0
registerX Unsigned byte 0 to 255 Only in BASIC 7.0 
registerY Unsigned byte 0 to 255 0Only in BASIC 7.0 
registerP Unsigned byte 0 to 255 Only in BASIC 7.0 
 
 
Purpose 
Call a machine-langauge subroutine.
 
 
Remarks 
This statement calls a non-BASIC (machine-language) program in memory (either RAM or ROM).  If it returns to BASIC, then this statement is like GOSUB.  However the machine-language software may take over the machine and never return to BASIC; in which case this statement is like GOTO.  On machines with more than 64K of system RAM, the BANK statement should be used prior to SYS, so BASIC will access the correct "memory".
 
In versions of BASIC prior to 7.0, setting up the A, X, and Y registers of the CPU for the start of the program was only possible with machine-specific POKEs.  In those versions, attempting to pass CPU registers like shown above for v7.0 would typically generate a SYNTAX ERROR.  However, because the called program completely takes over the machine, it may be written to actually read the text (if any) following the address.  Such cases are implementation-dependant, so I can't tell you what would happen; consult any documentation you have for that particular software.
 
Because this is a statement, and not a function (compare with USR), there is no official "return value."  However, in BASIC v7.0 the RREG statement may be used to return the A, X, Y, and P registers when the machine-language program ended, and in earlier versions PEEKing the addresses used to set the registers would accomplish the same thing.
 
In versions of BASIC before 7.0, the A, X, Y, and P registers that are passed to and returned from the machine language program are secret variables.
 
Similar to POKE, the SYS statement is typically used to accomplish things that are not possible (or extremely clumsy) with BASIC.  Some programs consist only of an SYS command!  These are machine-language programs designed to be started with BASIC.  (Most machine-language programs are not started with BASIC.)  For example, a variety of machine-language programs were developed for the Commodore 64 to allow BASIC programs access to the useful features of that machine (such as bitmap graphics and music) that are not practical with BASIC v2.
 
If the address or any register is a string, a TYPE MISMATCH ERROR occurs.  Otherwise if any are not legal (see table above) then ILLEGAL QUANTITY ERROR is generated.
 
The safe / useful set of address(s) depend on what is currently in memory and is very machine-specific; this statement is non-portable.  As such, there are no examples.
 
If the address points to a "break" opcode, or if a "break" opcode is executed while the ML program is running then either a machine-language monitor (see MONITOR) will start-up or, if the machine does not have an ML monitor, the system will "soft-reset" (just like pressing STOP + RESTORE on the keyboard).  Machines that do not have the MONITOR keyword (but do have an ML monitor) may be able to start the ML monitor by giving an address that contains a zero byte (a CPU "break" opcode).  For example SYS 5.  This is very machine-specific, and some machines do not have an ML monitor in ROM; they need a special cartridge or a monitor loaded into RAM.
 
If the address points to an "illegal" opcode (not neccessarily an undocumented opcode) or if one is ever executed while the ML program runs, the machine will "hard-lock": pressing STOP + RESTORE will not work.  The only way to recover from a "hard lock" is to press the Reset button, if available; otherwise the computer must be powered off!  This means you would loose all unsaved data, so be careful.
 
 
Compare With 
 
See Also 

© H2Obsession, 2014