The zero page or base page is the block of memory at the very beginning of a
computer
A computer is a machine that can be Computer programming, programmed to automatically Execution (computing), carry out sequences of arithmetic or logical operations (''computation''). Modern digital electronic computers can perform generic set ...
's
address space
In computing, an address space defines a range of discrete addresses, each of which may correspond to a network host, peripheral device, disk sector, a memory cell or other logical or physical entity.
For software programs to save and retrieve ...
; that is, the
page
Page most commonly refers to:
* Page (paper), one side of a leaf of paper, as in a book
Page, PAGE, pages, or paging may also refer to:
Roles
* Page (assistance occupation), a professional occupation
* Page (servant), traditionally a young m ...
whose starting address is zero. The size of a page depends on the context, and the significance of zero page memory versus higher addressed memory is highly dependent on machine architecture. For example, the
Motorola 6800
The 6800 ("''sixty-eight hundred''") is an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System (later dubbed ''68xx'') that also included serial and parall ...
and
MOS Technology 6502
The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") William Mensch and the moderator both pronounce the 6502 microprocessor as ''"sixty-five-oh-two"''. is an 8-bit computing, 8-bit microprocessor that was desi ...
processor families treat the first 256
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
s of
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
specially,
whereas many other processors do not.
Unlike more modern hardware, in the 1970s computer
RAM
Ram, ram, or RAM most commonly refers to:
* A male sheep
* Random-access memory, computer memory
* Ram Trucks, US, since 2009
** List of vehicles named Dodge Ram, trucks and vans
** Ram Pickup, produced by Ram Trucks
Ram, ram, or RAM may also ref ...
speed was similar to that of CPUs. Thus it made sense to have few registers and use the main memory as an extended pool of extra registers. In machines with a relatively wide
16-bit
16-bit microcomputers are microcomputers that use 16-bit microprocessors.
A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two ...
address bus
In computer architecture, a bus (historically also called a data highway or databus) is a communication system that transfers data between components inside a computer or between computers. It encompasses both hardware (e.g., wires, optical ...
and comparatively narrow
8-bit
In computer architecture, 8-bit integers or other data units are those that are 8 bits wide (1 octet). Also, 8-bit central processing unit (CPU) and arithmetic logic unit (ALU) architectures are those that are based on registers or data bu ...
data bus, calculating an address in memory could take several cycles. The zero page's one-byte address was smaller and therefore faster to read and calculate than other locations, making the zero page useful for high-performance code.
Zero page addressing now has mostly historical significance, since the developments in
integrated circuit
An integrated circuit (IC), also known as a microchip or simply chip, is a set of electronic circuits, consisting of various electronic components (such as transistors, resistors, and capacitors) and their interconnections. These components a ...
technology
Technology is the application of Conceptual model, conceptual knowledge to achieve practical goals, especially in a reproducible way. The word ''technology'' can also mean the products resulting from such efforts, including both tangible too ...
have made adding more registers to a CPU less expensive and CPU operations much faster than RAM accesses.
Size
The actual size of the zero page in bytes is determined by the
microprocessor
A microprocessor is a computer processor (computing), processor for which the data processing logic and control is included on a single integrated circuit (IC), or a small number of ICs. The microprocessor contains the arithmetic, logic, a ...
design and in older designs, is often equal to the largest value that can be referenced by the processor's indexing registers. For example, the aforementioned 8-bit processors have 8-bit index registers and a page size of 256 bytes. Therefore, their zero page extends from address 0 to address 255.
Computers with few CPU registers
In early computers, such as the
PDP-8
The PDP-8 is a family of 12-bit minicomputers that was produced by Digital Equipment Corporation (DEC). It was the first commercially successful minicomputer, with over 50,000 units sold during the model's lifetime. Its basic design follows the pi ...
, the zero page had a special fast
addressing mode
Addressing modes are an aspect of the instruction set architecture in most central processing unit (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how the machine language instructions ...
, which facilitated its use for temporary
storage of data and compensated for the paucity of
CPU 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), ...
s. The PDP-8 had only one register, so zero page addressing was essential. In the original
PDP-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 ...
KA-10 models, the available registers are simply the first 16 words,
36-bits long, of main memory. Those locations can be accessed as both registers and memory locations.
Unlike more modern hardware, 1970s-era computer
RAM
Ram, ram, or RAM most commonly refers to:
* A male sheep
* Random-access memory, computer memory
* Ram Trucks, US, since 2009
** List of vehicles named Dodge Ram, trucks and vans
** Ram Pickup, produced by Ram Trucks
Ram, ram, or RAM may also ref ...
was as fast as the CPU. Thus, it made sense to have few registers and use the main memory as an extended pool of extra registers. In machines with a
16-bit
16-bit microcomputers are microcomputers that use 16-bit microprocessors.
A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two ...
address bus
In computer architecture, a bus (historically also called a data highway or databus) is a communication system that transfers data between components inside a computer or between computers. It encompasses both hardware (e.g., wires, optical ...
and
8-bit
In computer architecture, 8-bit integers or other data units are those that are 8 bits wide (1 octet). Also, 8-bit central processing unit (CPU) and arithmetic logic unit (ALU) architectures are those that are based on registers or data bu ...
data bus, accessing zero page locations could be faster than accessing other locations. Since zero page locations could be addressed by a single
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
, the instructions accessing them could be shorter and hence faster-loading.
For example, the
MOS Technology 6502
The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") William Mensch and the moderator both pronounce the 6502 microprocessor as ''"sixty-five-oh-two"''. is an 8-bit computing, 8-bit microprocessor that was desi ...
family has only one general purpose register: the accumulator. To offset this limitation and gain a performance advantage, the 6502 is designed to make special use of the zero page, providing instructions whose
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s are eight bits, instead of 16, thus requiring fewer memory fetch cycles. Many
instructions are coded differently for zero page and non-zero page addresses; this is called ''zero-page addressing'' in 6502 terminology (it is called ''direct addressing'' in
Motorola 6800
The 6800 ("''sixty-eight hundred''") is an 8-bit microprocessor designed and first manufactured by Motorola in 1974. The MC6800 microprocessor was part of the M6800 Microcomputer System (later dubbed ''68xx'') that also included serial and parall ...
terminology; the
Western Design Center
The Western Design Center (WDC), located in Mesa, Arizona, is a company that develops intellectual property for, and licenses manufacture of, MOS Technology 65xx based microprocessors and microcontrollers. WDC was founded in 1978 by a former ...
65C816 also refers to zero page addressing as ''direct page addressing''):
LDA $12 ; zero page addressing
LDA $0012 ; absolute addressing
In 6502 assembly language, the above two instructions both accomplish the same thing: they load the value of memory location
$12
into the
.A
(accumulator) register (
$
is Motorola/MOS Technology assembly language notation for a hexadecimal number). However, the first instruction is only two bytes long and requires three clock cycles to complete. The second instruction is three bytes in length and requires four clock cycles to execute. This difference in execution time could become significant in repetitive code.
Some processors, such as the
Motorola 6809
The Motorola 6809 ("''sixty-eight-oh-nine''") is an 8-bit microprocessor with some 16-bit features. It was designed by Motorola's Terry Ritter and Joel Boney and introduced in 1978. Although source compatible with the earlier Motorola 6800, the ...
and the aforementioned WDC 65C816, implement a “direct page register” (
DP
) that tells the processor the starting address in
RAM
Ram, ram, or RAM most commonly refers to:
* A male sheep
* Random-access memory, computer memory
* Ram Trucks, US, since 2009
** List of vehicles named Dodge Ram, trucks and vans
** Ram Pickup, produced by Ram Trucks
Ram, ram, or RAM may also ref ...
of what is considered to be zero page. In this context, zero page addressing is notional; the actual access would not be to the physical zero page if
DP
is loaded with some address other than
$00
(or
$0000
in the case of the 65C816).
Interrupt vectors
Some computer architectures still reserve the beginning of address space for other purposes, though; for instance,
Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
x86
x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. Th ...
systems reserve the first 256 double-words of address space for the
interrupt vector table
An interrupt vector table (IVT) is a data structure that associates a list of interrupt handlers with a list of interrupt requests in a table of interrupt vectors. Each entry of the interrupt vector table, called an interrupt vector, is the addre ...
(IVT) if they run in
real mode
Real mode, also called real address mode, is an operating mode of all x86-compatible CPUs. The mode gets its name from the fact that addresses in real mode always correspond to real locations in memory. Real mode is characterized by a 20- bit s ...
.
A similar technique of using the zero page for hardware related vectors was employed in the ARM architecture. In badly written programs this could lead to "ofla" behaviour, where a program tries to read information from an unintended memory area, and treats executable code as data or vice versa. This is especially problematic if the zero page area is used to store system jump vectors and the firmware is tricked into overwriting them.
CP/M
In 8-bit
CP/M
CP/M, originally standing for Control Program/Monitor and later Control Program for Microcomputers, is a mass-market operating system created in 1974 for Intel 8080/Intel 8085, 85-based microcomputers by Gary Kildall of Digital Research, Dig ...
, the zero page is used for communication between the running program and the operating system.
Page addressing
In some processor architectures, like that of the
Intel 4004
The Intel 4004 was part of the 4 chip MCS-4 micro computer set, released by the Intel, Intel Corporation in November 1971; the 4004 being part of the first commercially marketed microprocessor chipset, and the first in a long line of List of I ...
4-bit processor, memory was divided into (256 byte) pages and special precautions had to be taken when the
control flow
In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an '' ...
crossed
page boundaries, as some
machine instruction
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonbi ...
s exhibited different behaviour if located in the last few instructions of a page, so that only few instructions were recommended to jump between pages.
Null pointers
Contrary to the zero page's original preferential use, some modern operating systems such as
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
,
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
,
Solaris
Solaris is the Latin word for sun.
It may refer to:
Arts and entertainment Literature, television and film
* ''Solaris'' (novel), a 1961 science fiction novel by Stanisław Lem
** ''Solaris'' (1968 film), directed by Boris Nirenburg
** ''Sol ...
,
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, and
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
actually make the zero page inaccessible to trap uses of
null pointer
In computing, a null pointer (sometimes shortened to nullptr or null) or null reference is a value saved for indicating that the Pointer (computer programming), pointer or reference (computer science), reference does not refer to a valid Object (c ...
s. Such pointer values may legitimately indicate uninitialized values or
sentinel node
In computer programming, a sentinel node is a specifically designated node used with linked lists and trees as a traversal path terminator. This type of node does not hold or reference any data managed by the data structure.
Benefits
Sentinel ...
s, but they do not point to valid objects.
Buggy code may try to access an object via a null pointer, and this can be trapped at the operating system level as a memory
access violation
In computing, a segmentation fault (often shortened to segfault) or access violation is a Interrupt, failure condition raised by hardware with memory protection, notifying an operating system (OS) the software has attempted to access a restricted ...
.
See also
*
Low memory – the first 64 KB of memory (segment 0) in DOS
*
Page boundary relocation
References
Further reading
*
*
* {{cite book , title=8086 Family Utilities - User's Guide for 8080/8085-Based Development Systems , chapter=1. Introduction: Segment Alignment , id=Order Number: 9800639-04 , edition=A620/5821 6K DD , version=Revision E , date=May 1982 , orig-year=1980, 1978 , publisher=
Intel Corporation
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and incorporated in Delaware. Intel designs, manufactures, and sells computer components such as central processing ...
, location=Santa Clara, California, USA , page=1-6 , url=http://bitsavers.trailing-edge.com/pdf/intel/ISIS_II/9800639-04E_8086_Famility_Utilities_Users_Guide_May82.pdf , access-date=2020-02-29 , url-status=live , archive-url=https://web.archive.org/web/20200229032355/http://bitsavers.trailing-edge.com/pdf/intel/ISIS_II/9800639-04E_8086_Famility_Utilities_Users_Guide_May82.pdf , archive-date=2020-02-29
Memory management