HOME

TheInfoList



OR:

In
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, e ...
, PEEK and POKE are commands used in some
high-level programming language In computer science, a high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ...
s for accessing the contents of a specific memory cell referenced by its
memory address In computing, a memory address is a reference to a specific memory location used at various levels by software and hardware. Memory addresses are fixed-length sequences of digits conventionally displayed and manipulated as unsigned integers. ...
. PEEK gets the byte located at the specified memory address. POKE sets the memory byte at the specified address. These commands originated with
machine code monitor A machine code monitor ( machine language monitor) is software that allows a user to enter commands to view and change memory locations on a computer, with options to load and save memory contents from/to secondary storage. Some full-featured m ...
s such as the
DECsystem-10 Digital Equipment Corporation (DEC)'s PDP-10, later marketed as the DECsystem-10, is a mainframe computer family manufactured beginning in 1966 and discontinued in 1983. 1970s models and beyond were marketed under the DECsystem-10 name, especi ...
monitor; these commands are particularly associated with the
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
programming language, though some other languages such as Pascal and
COMAL COMAL (''Common Algorithmic Language'') is a computer programming language developed in Denmark by Børge R. Christensen and Benedict Løfstedt and originally released in 1975. COMAL was one of the few structured programming languages that was a ...
also have these commands. These commands are comparable in their roles to
pointers Pointer may refer to: Places * Pointer, Kentucky * Pointers, New Jersey * Pointers Airport, Wasco County, Oregon, United States * The Pointers, a pair of rocks off Antarctica People with the name * Pointer (surname), a surname (including a lis ...
in the
C language C (''pronounced like the letter c'') is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities o ...
and some other programming languages. One of the earliest references to these commands in BASIC, if not the earliest, is in
Altair BASIC Altair BASIC is a discontinued interpreter for the BASIC programming language that ran on the MITS Altair 8800 and subsequent S-100 bus computers. It was Microsoft's first product (as Micro-Soft), distributed by MITS under a contract. Altair BASI ...
.Altair 8800 BASIC Reference_Manual 1975
Page 68 of PDF The PEEK and POKE commands were conceived in early personal computing systems to serve a variety of purposes, especially for modifying special memory-mapped
hardware register In digital electronics, especially computing, hardware registers are circuits typically composed of flip flops, often with many characteristics similar to memory, such as: * The ability to read or write multiple bits at a time, and * Using an ...
s to control particular functions of the computer such as the input/output peripherals. Alternatively programmers might use these commands to copy software or even to circumvent the intent of a particular piece of software (e.g. manipulate a game program to allow the user to cheat). Today it is unusual to control computer memory at such a low level using a high-level language like BASIC. As such the notions of ''PEEK'' and ''POKE'' commands are generally seen as antiquated. The terms ''peek'' and ''poke'' are sometimes used colloquially in computer programming to refer to memory access in general.


Statement syntax

The PEEK function and POKE commands are usually invoked as follows, either in
direct mode In computing, direct or immediate mode in an interactive programming system is the immediate execution of commands, statements, or expressions. In many interactive systems, most of these can both be included in programs or executed directly in ...
(entered and executed at the BASIC
prompt Prompt may refer to: Computing * Command prompt, characters indicating the computer is ready to accept input * Command Prompt, also known as cmd.exe or cmd, the command-line interpreter in some operating systems * Prompt (natural language), instr ...
) or in indirect mode (as part of a
program Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Progra ...
): integer_variable = PEEK(address) POKE address, value The ''address'' and ''value'' parameters may contain complex
expression Expression may refer to: Linguistics * Expression (linguistics), a word, phrase, or sentence * Fixed expression, a form of words with a specific meaning * Idiom, a type of fixed expression * Metaphorical expression, a particular word, phrase, o ...
s, as long as the evaluated expressions correspond to valid memory addresses or values, respectively. A valid ''address'' in this context is an address within the computer's address space, while a valid ''value'' is (typically) an unsigned value between zero and the maximum unsigned number that the minimum addressable unit (memory cell) may hold.


Memory cells and hardware registers

The address locations that are POKEd or PEEKed at may refer either to ordinary memory cells or to memory-mapped
hardware register In digital electronics, especially computing, hardware registers are circuits typically composed of flip flops, often with many characteristics similar to memory, such as: * The ability to read or write multiple bits at a time, and * Using an ...
s of I/O units or support chips such as
sound chip A sound chip is an integrated circuit (chip) designed to produce audio signals through digital, analog or mixed-mode electronics. Sound chips are typically fabricated on metal–oxide–semiconductor (MOS) mixed-signal chips that process ...
s and video graphics chips, or even to memory-mapped
register Register or registration may refer to: Arts entertainment, and media Music * Register (music), the relative "height" or range of a note, melody, part, instrument, etc. * ''Register'', a 2017 album by Travis Miller * Registration (organ), th ...
s of the CPU itself (which makes software implementations of powerful
machine code monitor A machine code monitor ( machine language monitor) is software that allows a user to enter commands to view and change memory locations on a computer, with options to load and save memory contents from/to secondary storage. Some full-featured m ...
s and
debugging In computer programming and software development, debugging is the process of finding and resolving '' bugs'' (defects or problems that prevent correct operation) within computer programs, software, or systems. Debugging tactics can involve in ...
/simulation tools possible). As an example of a POKE-driven support chip control scheme, the following POKE command is directed at a specific register of the
Commodore 64 The Commodore 64, also known as the C64, is an 8-bit home computer introduced in January 1982 by Commodore International (first shown at the Consumer Electronics Show, January 7–10, 1982, in Las Vegas). It has been listed in the Guinness ...
's built-in
VIC-II The VIC-II (Video Interface Chip II), specifically known as the MOS Technology 6567/8562/8564 (NTSC versions), 6569/8565/8566 ( PAL), is the microchip tasked with generating Y/C video signals (combined to composite video in the RF modulator) and ...
graphics chip, which will make the screen border turn black: POKE 53280, 0 A similar example from the Atari 8-bit family tells the
ANTIC Alphanumeric Television Interface Controller (ANTIC) is an LSI ASIC dedicated to generating 2D computer graphics to be shown on a television screen or computer display. Under the direction of Jay Miner, the chip was designed in 1977-1978 by ...
display driver to turn all text upside-down: POKE 755, 4 The difference between machines, and the importance and utility of the hard-wired memory locations, meant that "memory maps" of various machines were important documents. An example is ''
Mapping the Atari ''Mapping the Atari'', written by Ian Chadwick and published by COMPUTE! Publications in 1983, is a location-by-location explanation of the memory layout of the Atari 8-bit family of home computers. The introduction is by Optimized Systems So ...
'', which starts at location zero and mapped out the entire 64 kB memory of the Atari 8-bit systems location by location.


PEEK and POKE in other BASICs

North Star Computers North Star Computers Inc. (later styled as NorthStar) was an American computer company based in Berkeley, California existing between June 1976 (when according to popular rumor it was formed as "Kentucky Fried Computers") and 1989. Originally a mai ...
, a vendor from the early 1980s, offered their own dialect of BASIC with their NSDOS
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
. Concerned about possible legal issues, they renamed the commands EXAM and FILL. There were also BASIC dialects that used the reserved words MEMW and MEMR instead.
BBC BASIC BBC BASIC is a version of the BASIC programming language released in 1981 as the native programming language for the BBC Micro home/personal computer, providing a standardized language for a UK computer literacy project of the BBC. It was wr ...
, used on the
BBC Micro The British Broadcasting Corporation Microcomputer System, or BBC Micro, is a series of microcomputers and associated peripherals designed and built by Acorn Computers in the 1980s for the BBC Computer Literacy Project. Designed with an emphas ...
and other
Acorn Computers Acorn Computers Ltd. was a British computer company established in Cambridge, England, in 1978. The company produced a number of computers which were especially popular in the UK, including the Acorn Electron and the Acorn Archimedes. Acorn's ...
machines, did not feature the keywords ''PEEK'' and ''POKE'' but used the
question mark The question mark (also known as interrogation point, query, or eroteme in journalism) is a punctuation mark that indicates an interrogative clause or phrase in many languages. History In the fifth century, Syriac Bible manuscripts used ques ...
symbol (?), known as ''query'' in BBC BASIC, for both operations, as a function and command. For example: > DIM W% 4 : REM reserve 4 bytes of memory, pointed to by integer variable W% > ?W% = 42 : REM store constant 42; equivalent of 'POKE W%, 42' > PRINT ?W% : REM print the byte pointed to by W%; equivalent of 'PRINT PEEK(W%)' 42 32-bit values could be POKEd and PEEKed using the
exclamation mark The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
symbol (!), known as ''pling'', with the least significant byte first (
little-endian In computing, endianness, also known as byte sex, is the order or sequence of bytes of a word of digital data in computer memory. Endianness is primarily expressed as big-endian (BE) or little-endian (LE). A big-endian system stores the most si ...
). In addition, the address could be offset by specifying either query or pling ''after'' the address and following it with the offset: > !W% = &12345678 : REM ampersand (&) specifies hexadecimal > PRINT ~?W%, ~W%?3 : REM tilde (~) prints in hexadecimal 78 12 Strings of text could be PEEKed and POKEd in a similar way using the
Dollar sign The dollar sign, also known as peso sign, is a symbol consisting of a capital " S" crossed with one or two vertical strokes ($ or ), used to indicate the unit of various currencies around the world, including most currencies denominated "p ...
($). The end of the string is marked with the
Carriage return A carriage return, sometimes known as a cartridge return and often shortened to CR, or return, is a control character or mechanism used to reset a device's position to the beginning of a line of text. It is closely associated with the line feed ...
character (&0D in
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
); when read back, this terminating character is not returned. Offsets cannot be used with the dollar sign. > DIM S% 20 : REM reserve 20 bytes of memory pointed to by S% > $S% = "MINCE PIES" : REM store string 'MINCE PIES', terminated by &0D > PRINT $(S% + 6) : REM retrieve string, excluding &0D terminator, and starting at S% + 6 bytes PIES


16 and 32-bit versions

As most early home computers used 8-bit processors, PEEK or POKE values are between 0 and 255. Setting or reading a 16-bit value on such machines requires two commands, such as to read a 16-bit integer at address A, and followed by and to store a 16-bit integer V at address A. Some BASICs, even on 8-bit machines, have commands for reading and writing 16-bit values from memory.
BASIC XL Optimized Systems Software (OSS) was a company that produced disk operating systems, programming languages with integrated development environments, and applications primarily for the Atari 8-bit family of home computers. OSS was best known f ...
for the Atari 8-bit family uses a "D" (for "double") prefix: DPEEK and DPOKE The East-German "Kleincomputer" KC85/1 and KC87 calls them DEEK and DOKE. The
Sinclair QL The Sinclair QL (for ''Quantum Leap'') is a personal computer launched by Sinclair Research in 1984, as an upper-end counterpart to the ZX Spectrum. The QL was aimed at the serious home user and professional and executive users markets from small ...
has PEEK_W and POKE_W for 16-bit values and PEEK_L and POKE_L for 32-bit values. ST BASIC for the Atari ST uses the traditional names but allows defining 8/16/32 bit memory segments and addresses that determine the size.


POKEs as cheats

In the context of games for many 8-bit computers, users could load games into memory and, before launching them, modify specific memory addresses in order to
cheat Cheating generally describes various actions designed to subvert rules in order to obtain unfair advantages. This includes acts of bribery, cronyism and nepotism in any situation where individuals are given preference using inappropriate cr ...
, getting an unlimited number of lives, immunity, invisibility, etc. Such modifications were performed using POKE statements. The
Commodore 64 The Commodore 64, also known as the C64, is an 8-bit home computer introduced in January 1982 by Commodore International (first shown at the Consumer Electronics Show, January 7–10, 1982, in Las Vegas). It has been listed in the Guinness ...
,
ZX Spectrum The ZX Spectrum () is an 8-bit computing, 8-bit home computer that was developed by Sinclair Research. It was released in the United Kingdom on 23 April 1982, and became Britain's best-selling microcomputer. Referred to during development as t ...
and
Amstrad CPC The Amstrad CPC (short for ''Colour Personal Computer'') is a series of 8-bit home computers produced by Amstrad between 1984 and 1990. It was designed to compete in the mid-1980s home computer market dominated by the Commodore 64 and the Si ...
also allowed players with the relevant cartridges or
Multiface The Multiface was a hardware peripheral released by Romantic Robot for several 1980s home computers. The primary function of the device was to dump the computer's memory to external storage. Pressing a red button on the Multiface activated it. ...
add-on to freeze the running program, enter POKEs, and resume. For example, in ''
Knight Lore ''Knight Lore'' is a 1984 action-adventure game developed and published by Ultimate Play the Game, and written by company founders Chris and Tim Stamper. The game is known for its use of isometric graphics, which it further popularized in vid ...
'' for the
ZX Spectrum The ZX Spectrum () is an 8-bit computing, 8-bit home computer that was developed by Sinclair Research. It was released in the United Kingdom on 23 April 1982, and became Britain's best-selling microcomputer. Referred to during development as t ...
, immunity can be achieved with the following command: POKE 47196,201 In this case, the value 201 corresponds to a RET instruction, so that the game returns from a subroutine early before triggering
collision detection Collision detection is the computational problem of detecting the intersection of two or more objects. Collision detection is a classic issue of computational geometry and has applications in various computing fields, primarily in computer grap ...
. Magazines such as ''
Your Sinclair ''Your Sinclair'', or ''YS'' as it was commonly abbreviated, was a commercially published and printed British computer magazine for the Sinclair range of computers, mainly the ZX Spectrum. It was in circulation between 1984 and 1993. History T ...
'' published lists of such POKEs for games. Such codes were generally identified by reverse-engineering the machine code to locate the memory address containing the desired value that related to, for example, the number of lives, detection of collisions, etc. Using a 'POKE' cheat is more difficult in modern games, as many include anti-cheat or copy-protection measures that inhibit modification of the game's memory space. Modern operating systems enforce
virtual memory In computing, virtual memory, or virtual storage is a memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "creates the illusion to users of a very ...
protection schemes to deny external program access to non-shared memory (for example, separate
page table A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses. Virtual addresses are used by the program executed by the accessing process, ...
s for each application, hence inaccessible memory spaces).


Generic usage of POKE

"POKE" is sometimes used to refer to any direct manipulation of the contents of memory, rather than just via BASIC, particularly among people who learned computing on the 8-bit microcomputers of the late 1970s and early 1980s. BASIC was often the only language available on those machines (on home computers, usually present in
ROM Rom, or ROM may refer to: Biomechanics and medicine * Risk of mortality, a medical classification to estimate the likelihood of death for a patient * Rupture of membranes, a term used during pregnancy to describe a rupture of the amniotic sac * ...
), and therefore the obvious, and simplest, way to program in
machine language In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very ...
was to use BASIC to POKE the opcode values into memory. Doing much low-level coding like this usually came from lack of access to an
assembler Assembler may refer to: Arts and media * Nobukazu Takemura, avant-garde electronic musician, stage name Assembler * Assemblers, a fictional race in the ''Star Wars'' universe * Assemblers, an alternative name of the superhero group Champions of ...
. An example of the generic usage of POKE and PEEK is in Visual Basic for Windows, where DDE can be achieved with the LinkPoke keyword.


See also

*
Killer poke In computer jargon, a killer poke is a method of inducing physical hardware damage on a machine or its peripherals by the insertion of invalid values, via, for example, BASIC's POKE command, into a memory-mapped control register. The term is ...
*
Type-in program A type-in program or type-in listing was computer source code printed in a home computer magazine or book. It was meant to be entered via the keyboard by the reader and then saved to cassette tape or floppy disk. The result was a usable game, ...
*
Self-modifying code In computer science, self-modifying code (SMC) is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code, ...
*
Pointer (computer programming) In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware. A pointer ''ref ...


References

{{Authority control Microcomputer software BASIC commands Cheating in video games Computer memory