SYS
BASIC keyword | |
Keyword: | SYS |
Abbreviation: | S Shift+Y |
Type: | Command |
Token code: | 158/$9E |
Handling routine in BASIC ROM: |
57642–57685 $E12A–E155 |
List of all BASIC keywords |
Remark: This article describes the BASIC command SYS in BASIC V2 at the Commodore 64.
Typ: Command General Programming-Syntax: SYS <memory adress>
SYS is a command in Commodore BASIC V2, that tells the processor to execute the machine language subroutine at a specific address.
The <Address> parameter is a 16-bit unsigned integer, i.e. an integer in the range 0 thru 65535, or $0000 thru $FFFF. If the given address is outside these limits, the C64 will report an ?ILLEGAL QUANTITY ERROR.
Passing parameters via registers[edit | edit source]
Before calling the specified address, SYS “loads” the accumulator, the X and the Y index register, and the status register with the bytes stored at addresses 780–783/$030C–030F: From BASIC, one can set up parameters and data here, to be processed by the machine language routine. When the routine at the specified address returns control to BASIC (via an RTS instruction), SYS immediately saves the contents of the Accumulator, the X and Y index registers, and the status register back into the 780–783 memory range: This can be used to transfer results from the machine language routine to BASIC for further processing.
Address | Register |
---|---|
780 | Accumulator |
781 | X Register |
782 | Y Register |
783 | Status Register /Flags |
Passing parameters through BASIC[edit | edit source]
In order to pass parameters from BASIC to the machine code routine, one can also exploit the “mechanisms” in BASIC ROM that handles parameters in other BASIC commands, using routines like e.g.
- CHKCOM (at 44797/$AEFD) which checks that the next character in the command is a comma
- GETBYT (at 47006/$B79E) which reads an unsigned byte parameter
- GETPAR (at 47083/$B7EB) which reads a 16-bit unsigned integer parameter followed by a comma followed by an 8-bit unsigned integer parameter
See also: Tim Pickett: "Borrowing ML From BASIC"; COMPUTE! Issue 67; December 1985, p.10
Examples[edit | edit source]
- BASIC 2.0
SYS 64738
Reset
SYS 49152
Start a machine code program, which is beginning at memory map address 49152 ($C000).
POKE 211,C:POKE 214, LN: SYS 58640
Using a system routine, which is positioning the cursor at column (C) and line (LN)
- BASIC 7.0
SYS 7168,1,2,3,255
Output: PC SR AC XR YR SP ; 01C02 FF 01 02 03 F6
New setting Y register:
SYS 7168,,,9
Other parameters for a calling routine:
SYS F1,,,,,A$,15
Links[edit | edit source]
ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT