In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, an opcode prefix is an numeric value that alters the function of a following
opcode
In computing, an opcode (abbreviated from operation code) is an enumerated value that specifies the operation to be performed. Opcodes are employed in hardware devices such as arithmetic logic units (ALUs), central processing units (CPUs), and ...
. On some
instruction set architecture
In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
s multiple opcode prefixes are allowed sequentially, with all combining to alter the subsequent opcode. The opcode prefix is a portion of a larger
machine language
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 nonb ...
instruction that specifies the operation to be performed.
In addition to the opcode, some instructions specify the
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 the operation will act upon. Opcode prefixes may alter the number or size of the operands.
RISC
In electronics and computer science, a reduced instruction set computer (RISC) is a computer architecture designed to simplify the individual instructions given to the computer to accomplish tasks. Compared to the instructions given to a comp ...
processors do not use opcode prefixes.
Types of prefixes
Opcode prefixes generally fall into two categories:
# Opcode prefixes that alter subsequent opcode functions.
# Opcode prefixes that enable an alternate set of opcodes. This is analogous to the shift key on a keyboard. In this way, instruction sets can be extended by adding a subset of new instructions by reusing existing reserved opcodes.
Example opcode prefixes
The following is not intended to be an exhaustive list of opcode prefixes but instead is intended to show how opcode prefixes have been used in various CPU instruction set architectures.
Microcontroller
The
National Semiconductor
National Semiconductor Corporation was an United States of America, American Semiconductor manufacturing, semiconductor manufacturer, which specialized in analogue electronics, analog devices and subsystems, formerly headquartered in Santa Clara, ...
COP8 is an 8-bit
microcontroller
A microcontroller (MC, uC, or μC) or microcontroller unit (MCU) is a small computer on a single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals. Pro ...
introduced in 1988. COP8 is an enhancement to National's earlier
COP400 4-bit microcontroller family. It uses an opcode prefix to alter its operands.
Normally, absolute RAM addressing is only directly encoded for just four instructions:
LD A,''addr8''
,
X A,''addr8''
,
IFEQ ''addr8'',#''imm8''
, and
LD ''addr8'',#''imm8''
. A two-byte opcode prefix may be prefixed to any other instruction that normally uses the B index register to access memory to convert that instruction to absolute RAM addressing. The prefix is 0xBD followed by an 8-bit absolute address. This prefix is unusual in that it is two bytes instead of one.
8-bit microprocessor
The
Zilog Z80
The Zilog Z80 is an 8-bit computing, 8-bit microprocessor designed by Zilog that played an important role in the evolution of early personal computing. Launched in 1976, it was designed to be Backward compatibility, software-compatible with the ...
is an 8-bit microprocessor that was launched in 1976. It was designed to be
backward software-compatible with the
Intel 8080
The Intel 8080 is Intel's second 8-bit computing, 8-bit microprocessor. Introduced in April 1974, the 8080 was an enhanced successor to the earlier Intel 8008 microprocessor, although without binary compatibility.'' Electronic News'' was a week ...
. It uses opcode prefixes to both alter its operands and to extend its instruction set.
In order to access operands in its new IX and IY registers, 0xDD or 0xFE is prefixed to the old 8080 instructions, allowing those instructions to substitute IX or IY, respectively, for HL. In cases where (HL) is used, (iX+disp) and (IY+disp) addressing modes are substituted.
0xCB and 0xED enable new instructions not found on the 8080. Prefixes can be combined: The 0xDD or 0xFE IX/IY prefixes can prefix any 0xCB prefixed instruction that uses HL.
16-bit microprocessor
The
Intel 8086
The 8086 (also called iAPX 86) is a 16-bit computing, 16-bit microprocessor chip designed by Intel between early 1976 and June 8, 1978, when it was released. The Intel 8088, released July 1, 1979, is a slightly modified chip with an external 8-b ...
and
8088
The Intel 8088 ("''eighty-eighty-eight''", also called iAPX 88) microprocessor is a variant of the Intel 8086. Introduced on June 1, 1979, the 8088 has an eight-bit external data bus instead of the 16-bit bus of the 8086. The 16-bit registers ...
have three types of prefixes, all which can be combined
[ There is a bug in the 8086 that causes multiple prefixes on string operations to be forgotten when an interrupt is acknowledged.] to alter some subsequent instructions.
''Segment override:'' Normally the data segment (DS) is used for most data accesses and the stack segment (SS) is used for any accesses involving BP or SP. One-byte segment override prefixes are provided to substitute ES, CS, SS, or DS.
''Repeat:'' String instructions
LODS
,
STOS
,
MOVS
,
CMPS
, and
SCAS
normally execute just one iteration. If a
REP
prefix is added to any string instruction, it will repeat CX times. The
CMPS
and
SCAS
instructions might terminate early if their equal or not equal conditions are satisfied. These instructions can be combined with segment override prefix for the source string.
''Lock:'' The
LOCK
prefix is used with a
read-modify-write instructions such as
INC
,
DEC
, or
XCHG
to insure that another bus master cannot interfere with the read or write operation.
LOCK
can be combined with segment override prefix.
64-bit microprocessor
AMD64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new operating modes: 64-bit mode an ...
or
x86-64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit extension of the x86 instruction set architecture, instruction set. It was announced in 1999 and first available in the AMD Opteron family in 2003. It introduces two new ope ...
is a 64-bit extension of the
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 ...
instruction set. It was announced in 1999 and first available in the
AMD Opteron family in 2003. It introduced a
REX opcode prefix that provides additional space for encoding 64-bit addressing modes and the additional eight integer registers present in the x86-64 architecture.
References
Notes
{{reflist, group=note, liststyle=lower-roman
Machine code