opcode
termKept in this browser · My desk
The part of a machine instruction that says which operation to perform; its mnemonic is the name assembly language gives it.
Reading an opcode table is the first skill of hand assembly and of disassembly. Opcodes are not universal: the byte 78 is MOV A,B in Intel's 8080 manual and LD A,B in Zilog's Z80 manual, the same machine operation under two companies' names; and on x86 one opcode byte can stand for several operations, told apart by three bits of the following ModR/M byte.
What it is. An opcode (operation code) is the field of a machine instruction that selects the operation; the rest of the instruction names the operands. Assembly language gives each opcode a mnemonic, and the processor's manual is, at bottom, a table from bit patterns to operations. The idea is not limited to silicon: every virtual machine, from the Java Virtual Machine (JVM) to CPython and WebAssembly, defines its own opcodes.
On x86. The Intel Software Developer's Manual (SDM) lists one to three primary opcode bytes per instruction and writes the rest of the encoding as notation: /digit means "the reg field contains the digit that provides an extension to the instruction's opcode", so FF /1 is DEC while FF /0 is INC; /r means the ModR/M byte holds a register operand and an r/m operand; +rd means the low three bits of the opcode byte name the register, as in B8+rd for MOV r32, imm32. The manual also defines a mnemonic as "a reserved name for a class of instruction opcodes which have the same function", which is why 74 is listed as both JE and JZ.
A decode, byte by byte. The x86-64 bytes 48 01 F8 show the parts working together. 48 is a REX prefix, 0100WRXB with W = 1, which selects 64-bit operands; 01 is the opcode, listed as REX.W + 01 /r, ADD r/m64, r64; F8 is the ModR/M byte, 11 111 000: mod 11 means both operands are registers, reg 111 names RDI and r/m 000 names RAX. The instruction is add rax, rdi, and the opcode byte alone said only "add a register to a register or memory operand"; the prefix chose the width and the ModR/M byte chose the operands. Opcodes that do not fit in one byte begin with the escape byte 0F, which is why so many later x86 instructions, UD2 among them, start with it.
Opcodes with a special job. Some x86 opcodes exist for tools rather than arithmetic. 90 is NOP, the "One byte no-operation instruction" (Vol. 2B, p. 4-159). CC is INT3, which the manual describes as "Generate breakpoint trap" (Vol. 2A, p. 3-466); being one byte long, it can replace the first byte of any instruction. And 0F 0B is UD2, one of the instructions defined only to "Raise invalid opcode exception", so that a program can mark a place execution must never reach. Every byte value that is not a valid opcode in the current mode raises the same exception, which is how a processor reacts to data it was pointed at by mistake.
On fixed-length machines. RISC-V puts a 7-bit opcode field in bits 6 to 0 of every 32-bit instruction and refines it with funct3 and funct7: ADD and SUB share opcode 0110011 and funct3 000 and differ only in funct7. AArch64 has no single opcode field; each encoding in the Arm manual is a pattern of fixed bits around the operand fields.
On 8-bit machines. The Z80 manual gives ADD A, r as 10 000 r and LD r, r' as 01 r r'; Intel's 8080 manual gives MOV r1,r2 as 01DDDSSS; the 6502 manual tabulates each addressing mode with its own opcode, LDA immediate A9, LDA zero page A5. The same byte can carry two vendors' names: 78 is MOV A,B in Intel's 8080 manual and LD A,B in Zilog's Z80 manual, one machine operation under two mnemonics. One lesson from the Z80 manual is that tables beat single pages: its XOR page prints OR's codes, while its opcode table gives XOR A correctly as AF.
The first mnemonics. On the EDSAC of 1949 the opcode was the five most significant bits of a 17-bit order, written as a letter. David Wheeler's notes say Maurice Wilkes devised the orders and Wheeler himself suggested the letters, trying to make them "as mnemonic as possible", with odd exceptions: M could not be used for multiply, and J was not used for jump "because the operation was then thought of as 'transfer of control'". The habit of naming each opcode with a short memorable word starts there.
In virtual machines. The Java Virtual Machine Specification has a whole chapter, Opcode Mnemonics by Opcode, mapping each byte to its instruction: 0x00 is nop, 0x60 iadd; 0xca (breakpoint) and 0xfe and 0xff (impdep1 and impdep2) are reserved, and "Opcode value 186 was not used prior to Java SE 7". WebAssembly says plainly that "Each opcode is represented by a single byte", with 0x00 for unreachable, 0x01 for nop and 0x6A for i32.add, and admits that the byte codes "are historical and do not follow a consistent pattern". CPython's opcodes, by contrast, are an implementation detail: its dis documentation warns that no guarantees are made that bytecode "will not be added, removed, or changed between versions of Python", and since Python 3.6 every instruction takes 2 bytes.
What goes wrong. The same byte means different things in different modes (40H to 4FH are INC and DEC in 32-bit x86 code and REX prefixes in 64-bit code), so an opcode table is only valid with its mode. Manuals contain errors, vendors rename each other's instructions, and a virtual machine's opcode numbers can change between releases. Disassemblers that start in the middle of an instruction read operand bytes as opcodes and produce a plausible but false listing, the property return-oriented programming exploits.
Neighbours. The opcode lives inside machine code, its mnemonic in assembly language, its meaning in the instruction set architecture, and its operands usually in registers. Brazilian practice says opcode or código de operação.
Also known as: operation code, op code, código de operação, instruction opcode
Sources
- Intel, Intel 64 and IA-32 Architectures Software Developer's Manual, order 325462-093: instruction format of optional prefixes, one to three opcode bytes, ModR/M, SIB, displacement and immediate (Vol. 2A, p. 2-1); the 15-byte limit (Vol. 3A, p. 7-44); the label: mnemonic argument notation and the definition of a mnemonic as a reserved name for a class of opcodes with the same function (Vol. 1, p. 1-7) (read 2026-11-23)
- Intel SDM 325462-093: REX.W + 01 /r ADD r/m64, r64 (Vol. 2A, p. 3-14); 31 /r XOR (Vol. 2D, p. 6-40); C3 RET (Vol. 2B, p. 4-569); ModR/M Table 2-2 (Vol. 2A, p. 2-6); REX fields 0100WRXB (p. 2-9); /digit and /r notation (p. 3-2) (read 2026-11-23)
- RISC-V International, The RISC-V Instruction Set Manual Volume I: Unprivileged Architecture, version 20250508: designed for research and education (p. 12); instructions stored as 16-bit little-endian parcels (p. 19); x0 hardwired to zero (p. 23); the RV32I listing with opcode, funct3 and funct7 fields (p. 609); the compressed extension's 25-30% code-size reduction (p. 160) (read 2026-11-23)
- Zilog, Z80 Family CPU User Manual UM008005-0205: register set (p. 1); LD r, r' is 01 r r' (p. 81); ADD A, r is 10 000 r (p. 140); DJNZ is 10 followed by e-2, and the assembler adjusts for the incremented PC (p. 253); the XOR page prints OR's codes while the opcode table gives XOR A as AF (pp. 60 and 156) (read 2026-11-23)
- Intel, 8080/8085 Assembly Language Programming Manual 9800301C, November 1978: MOV r1,r2 is 01DDDSSS with B = 000 and A = 111; RET is 11001001 (pp. A-1 to A-3) (read 2026-11-23)
- MOS Technology, MCS6500 Microcomputer Family Programming Manual, 6500-50A, January 1976: instruction summary opcodes such as LDA immediate A9, ADC zero page 65, BNE D0 and RTS 60 (pp. B-3 to B-26); branch range of +127 to -128 (p. 42) (read 2026-11-23)
- Intel SDM 325462-093: NP 90 NOP, one-byte no-operation (Vol. 2B, p. 4-159); CC INT3, generate breakpoint trap (Vol. 2A, p. 3-466); 0F 0B UD2, with UD0 and UD1, raise invalid opcode exception (read 2026-11-23)
- The Java Virtual Machine Specification, Java SE 21, chapter 7, Opcode Mnemonics by Opcode: 00 (0x00) nop, 96 (0x60) iadd; reserved opcodes 202 (0xca) breakpoint, 254 (0xfe) impdep1 and 255 (0xff) impdep2; opcode value 186 not used prior to Java SE 7 (read 2026-11-23)
- WebAssembly Core Specification, Binary Format, Instructions: each opcode is a single byte followed by immediates; 0x00 unreachable, 0x01 nop, 0x6A i32.add; the byte codes 'are historical and do not follow a consistent pattern' (read 2026-11-23)
- Python documentation, dis: CPython bytecode is an implementation detail with no guarantee of stability between versions; since 3.6 every instruction uses 2 bytes (read 2026-11-23)
- University of Cambridge Computer Laboratory, David Wheeler, The EDSAC Order Code: Explanatory Notes: orders devised by Maurice Wilkes; Wheeler suggested the letters, made as mnemonic as possible; M not used for multiply, J not used for jump because the operation was thought of as 'transfer of control'; five most significant bits give the order type (read 2026-11-23)