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


Keyword Abbreviation Token (hex) Version(s) Classification
POKE P{Shift+O} 97 1.0 to 2.x, 4.x Command and Statement
POKE  PO{Shift+K}  97  3.5, 7.0  Command and Statement 

POKE address value
Parameters Type Legal Value(s) Default Value Note(s)
address Unsigned integer
0 to 65535
Pokes to ROM may "bleed" into underlying RAM.
value Unsigned byte
0 to 255
Write contents of "memory".
This statement sets a value in "memory" which is typically RAM and can later be recalled with PEEK, or it may be (depending on the machine and the address) an I/O register instead.  In the later case, the value may not be retrievable, depending on the characteristics of the particular I/O register.  On machines with more than 64K of system RAM, the BANK statement should be used prior to POKE, so BASIC will access the correct "memory".
POKE is typically used to set (or alter) some feature of the computer that is not directly available from BASIC.  For example, on the C64, a POKE to address 53281 will change the background screen color (the color depends on the value).  In this case, the address corresponds to a VIC-II I/O register (not RAM).  The C64 has BASIC 2.1, but some later versions provide a BASIC command (COLOR) to set the screen color.  Another example is to POKE an address (or two) in RAM that will disable the STOP key so the user can't "break" a BASIC program.  This is an example of modifying the system behavior.
Another use, more common on versions without BLOAD, is to POKE a machine-language program into RAM.  Because a program is usually many many bytes, individual POKEs are not done, but a loop (with FOR/NEXT or DO/LOOP) is used in conjunction with DATA and READ statements.  The same method may rarely be used to store other non-program data into RAM, such as a custom font.  A combination of this method (POKE DATA that is READ in a LOOP) with the previous (writing to I/O registers) may sometimes be used to play music.
If the address or value is a string, a TYPE MISMATCH ERROR occurs.  Otherwise if either is not legal (see table above) then ILLEGAL QUANTITY ERROR is generated.
You can think of POKE as a machine-language equivalant of BASIC's LET.  Either way you can (generally) save a value; the main difference is that LET sets a BASIC variables while POKE sets a machine "variable" (using a loose definition).  To read a value from "memory", see PEEK.
The safe / useful set of address and value are very machine-specific; this statement is very non-portable.  As such, there are no examples... okay one stupid example that should be safe on any CBM machine.
POKE 254,7


POKE 254,-7

Compare With  
Contrast With  
See Also  

© H2Obsession, 2014