HOME

TheInfoList




In
computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform in ...
, machine code is any
low-level programming language A low-level programming language is a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming languages ar ...
, consisting of machine language
instructions Instruction or instructions may refer to: Computing * Instruction, one operation of a processor within a computer architecture instruction set * Computer program, a collection of instructions Music * Instruction (band), a 2002 rock band from New Y ...
, which are used to control a computer's
central processing unit A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuit 200px, A circuit built on a printed circuit board (PCB). An electronic circuit is composed of individual electroni ...

central processing unit
(CPU). Each instruction causes the CPU to perform a very specific task, such as a load, a store, a jump, or an
arithmetic logic unit 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 computer hardware , hardware and softw ...
(ALU) operation on one or more units of data in the CPU's
register A register is an authoritative list of one kind of information. 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. * ''Regis ...
s or
memory Memory is the faculty of the by which or is , stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If s could not be remembered, it would be impossible for language, r ...
. Machine code is a strictly numerical language which is designed to run as fast as possible, and may be considered as the lowest-level representation of a
compiled In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiled
or assembled computer program or as a primitive and
hardware Hardware may refer to: Technology Computing and electronics * Computer hardware, physical parts of a computer * Digital electronics, electronics that operate on digital signals * Electronic component, device in an electronic system used to affect e ...

hardware
-dependent programming language. While it is possible to write programs directly in machine code, managing individual bits and calculating numerical addresses and constants manually is tedious and error-prone. For this reason, programs are very rarely written directly in machine code in modern contexts, but may be done for low level
debugging In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gener ...

debugging
, program
patching Patching is a small village and civil parish that lies amid the fields and woods of the southern slopes of the South Downs in the South Downs National Park, National Park in the Arun District, Arun District of West Sussex, England. It has a vis ...
(especially when assembler source is not available) and assembly language
disassembly A disassembler is a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a programming language ...
. The majority of practical programs today are written in higher-level languages or assembly language. The source code is then translated to executable machine code by utilities such as
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiler
s,
assemblers Assembler may refer to: Arts and media * Nobukazu Takemura Nobukazu Takemura (竹村延和 ''Takemura Nobukazu'') is a Japanese musician and artist. Born in Hirakata, Osaka in August 1968, he became interested in music at a young age by listenin ...
, and linkers, with the important exception of interpreted programs, which are not translated into machine code. However, the '' interpreter'' itself, which may be seen as an executor or processor performing the instructions of the source code, typically consists of directly executable machine code (generated from assembly or high-level language source code). Machine code is by definition the lowest level of programming detail visible to the programmer, but internally many processors use
microcode In processor design Processor design is a subfield of computer engineering and electronics engineering (fabrication) that deals with creating a processor (computing), processor, a key component of computer hardware. The design process involves ch ...
or optimise and transform machine code instructions into sequences of
micro-ops In computer central processing units, micro-operations (also known as a micro-ops or μops, historically also as micro-actions) are detailed low-level instructions used in some designs to implement complex machine instructions (sometimes termed ma ...
. This is not generally considered to be a machine code.


Instruction set

Every processor or processor family has its own
instruction set In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algo ...
. Instructions are patterns of
bit The bit is a basic unit of information in computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an algorithm (Euclid's algo ...
s, digits or characters that correspond to machine commands. Thus, the instruction set is specific to a class of processors using (mostly) the same architecture. Successor or derivative processor designs often include instructions of a predecessor and may add new additional instructions. Occasionally, a successor design will discontinue or alter the meaning of some instruction code (typically because it is needed for new purposes), affecting code compatibility to some extent; even compatible processors may show slightly different behavior for some instructions, but this is rarely a problem. Systems may also differ in other details, such as memory arrangement, operating systems, or peripheral devices. Because a program normally relies on such factors, different systems will typically not run the same machine code, even when the same type of processor is used. A processor's instruction set may have all instructions of the same length, or it may have variable-length instructions. How the patterns are organized varies with the particular architecture and type of instruction. Most instructions have one or more
opcode In computing, an opcode (abbreviated from operation code, also known as instruction machine code, instruction code, instruction syllable, instruction parcel or opstring) is the portion of a machine code, machine language instruction (computer sc ...
fields which specifies the basic instruction type (such as arithmetic, logical, jump, etc.), the operation (such as add or compare), and other fields that may give the type of 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. Example The following arithmetic expression shows an example of operators and operands: :3 + 6 = 9 In the above example, ...
(s), the
addressing mode Addressing modes are an aspect of the instruction set architecture In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions described b ...
(s), the addressing offset(s) or index, or the operand value itself (such constant operands contained in an instruction are called ''immediate''). Not all machines or individual instructions have explicit operands. An
accumulator machine In a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as Computer program, programs. These progr ...
has a combined left operand and result in an implicit accumulator for most arithmetic instructions. Other architectures (such as 8086 and the x86-family) have accumulator versions of common instructions, with the accumulator regarded as one of the general registers by longer instructions. A
stack machine In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algori ...
has most or all of its operands on an implicit stack. Special purpose instructions also often lack explicit operands (CPUID in the x86 architecture writes values into four implicit destination registers, for instance). This distinction between explicit and implicit operands is important in code generators, especially in the
register allocation In compiler optimization 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 computer hardwa ...
and live range tracking parts. A good code optimizer can track implicit as well as explicit operands which may allow more frequent
constant propagation Constant folding and constant propagation are related compiler optimizations used by many modern compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language ...
,
constant folding Constant folding and constant propagation are related compiler optimizations used by many modern compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language ...
of registers (a register assigned the result of a constant expression freed up by replacing it by that constant) and other code enhancements.


Programs

A
computer program In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarative programming, a ''computer program'' is a Set (mathematics), set of instructions. A comp ...
is a list of instructions that can be executed by a
central processing unit A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuit 200px, A circuit built on a printed circuit board (PCB). An electronic circuit is composed of individual electroni ...

central processing unit
(CPU). A program's execution is done in order for the CPU that is executing it to solve a problem and thus accomplish a result. While simple processors are able to execute instructions one after another,
superscalar Processor board of a CRAY T3e supercomputer with four ''superscalar'' Alpha 21164 processors A superscalar processor is a CPU A central processing unit (CPU), also called a central processor, main processor or just processor, is the el ...
processors are capable of executing many instructions simultaneously.
Program flow In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algor ...
may be influenced by special 'jump' instructions that transfer execution to an address (and hence instruction) other than the next numerically sequential address. Whether these
conditional jump A branch is an instruction in a computer program that can cause a computer to begin executing a different instruction sequence and thus deviate from its default behavior of executing instructions in order. Branch (or ''branching'', ''branched' ...
s occur is dependent upon a condition such as a value being greater than, less than, or equal to another value.


Assembly languages

A much more human friendly rendition of machine language, called
assembly language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, genera ...
, uses mnemonic codes to refer to machine code instructions, rather than using the instructions' numeric values directly, and uses symbolic names to refer to storage locations and sometimes registers. For example, on the
Zilog Z80 The Z80 is an 8-bit In computer architecture, 8-bit integer (computer science), integers or other data#Uses of data in computing, data units are those that are 8 bits wide (1 octet). Also, 8-bit central processing unit, CPU and arithmeti ...

Zilog Z80
processor, the machine code 00000101, which causes the CPU to decrement the B
processor register Processor may refer to: Computing Hardware * Processor (computing) **Central processing unit (CPU), the hardware within a computer that executes a program *** Microprocessor, a central processing unit contained on a single integrated circuit (I ...
, would be represented in assembly language as DEC B.


Example

The
MIPS architecture MIPS (Microprocessor without Interlocked Pipelined Stages) is a reduced instruction set computer A reduced instruction set computer, or RISC (), is a computer with a small, highly optimized set of instructions, rather than the more special ...
provides a specific example for a machine code whose instructions are always 32 bits long. The general type of instruction is given by the ''op'' (operation) field, the highest 6 bits. J-type (jump) and I-type (immediate) instructions are fully specified by ''op''. R-type (register) instructions include an additional field ''funct'' to determine the exact operation. The fields used in these types are: 6 5 5 5 5 6 bits rs , rt , rd , shamt, funct R-type rs , rt , address/immediate I-type target address J-type ''rs'', ''rt'', and ''rd'' indicate register operands; ''shamt'' gives a shift amount; and the ''address'' or ''immediate'' fields contain an operand directly. For example, adding the registers 1 and 2 and placing the result in register 6 is encoded: rs , rt , rd , shamt, funct 0 1 2 6 0 32 decimal 000000 00001 00010 00110 00000 100000 binary Load a value into register 8, taken from the memory cell 68 cells after the location listed in register 3: rs , rt , address/immediate 35 3 8 68 decimal 100011 00011 01000 00000 00001 000100 binary Jumping to the address 1024: target address 2 1024 decimal 000010 00000 00000 00000 10000 000000 binary


Overlapping instructions

On processor architectures with
variable-length instruction set In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algo ...
s (such as
Intel Intel Corporation is an American multinational corporation A multinational company (MNC) is a corporate A corporation is an organization—usually a group of people or a company A company, abbreviated as co., is a Legal personalit ...

Intel
's
x86 x86 is a family of instruction set architecture In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions described by that ISA, ...

x86
processor family) it is, within the limits of the control-flow resynchronizing phenomenon known as the Kruskal Count, sometimes possible through opcode-level programming to deliberately arrange the resulting code so that two code paths share a common fragment of opcode sequences. These are called ''overlapping instructions'', ''overlapping opcodes'', ''overlapping code'', ''overlapped code'', ''instruction scission'', or ''jump into the middle of an instruction'', and represent a form of superposition. In the 1970s and 1980s, overlapping instructions were sometimes used to preserve memory space. One example were in the implementation of error tables in
Microsoft Microsoft Corporation is an American multinational corporation, multinational technology company, technology corporation which produces Software, computer software, consumer electronics, personal computers, and related services. Its best-know ...

Microsoft
's
Altair BASIC Altair BASIC is a discontinued interpreter for the BASIC programming language BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages whos ...
, where ''interleaved instructions'' mutually shared their instruction bytes. The technique is rarely used today, but might still be necessary to resort to in areas where extreme optimization for size is necessary on byte-level such as in the implementation of
boot loader A bootloader is software that is responsible for booting In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an al ...
s which have to fit into
boot sector A boot sector is the disk sector, sector of a persistent data storage device (e.g., hard disk, floppy disk, optical disc, etc.) which contains machine code to be loaded into random-access memory (RAM) and then executed by a computer system's bu ...
s. It is also sometimes used as a
code obfuscation In software development, obfuscation is the deliberate act of creating source code, source or machine code that is difficult for humans to understand. Like obfuscation in natural language, it may use needlessly roundabout expressions to compose ...
technique as a measure against
disassembly A disassembler is a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a programming language ...
and tampering. The principle is also utilized in shared code sequences of fat binaries which must run on multiple instruction-set-incompatible processor platforms. This property is also used to find ''unintended instructions'' (called
gadget A gadget is a mechanical device or any ingenious article. Gadgets are sometimes referred to as ''wikt:gizmo, gizmos''. History The etymology of the word is disputed. The word first appears as reference to an 18th-century tool in glassmaking that ...
s) in existing code repositories and is utilized in
return-oriented programmingReturn-oriented programming (ROP) is a computer security exploit technique that allows an attacker to execute code in the presence of security defenses such as executable space protection and code signing. In this technique, an attacker gains contro ...
as alternative to
code injection Code injection is the exploitation of a computer bug A software bug is an error, flaw or fault in a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A ...
for exploits such as
return-to-libc attack A "return-to-libc" attack is a computer security Computer security, cybersecurity, or information technology security (IT security) is the protection of computer system A computer is a machine that can be programmed to carry out Sequence ...
s.


Relationship to microcode

In some
computer architecture In computer engineering, computer architecture is a set of rules and methods that describe the functionality, organization, and implementation of computer systems. The architecture of a system refers to its structure in terms of separately specifi ...
s, the machine code is implemented by an even more fundamental underlying layer called
microcode In processor design Processor design is a subfield of computer engineering and electronics engineering (fabrication) that deals with creating a processor (computing), processor, a key component of computer hardware. The design process involves ch ...
, providing a common machine language interface across a line or family of different models of computer with widely different underlying
dataflow In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an algorithm (Euclid's algorithm) for calculating the greatest commo ...

dataflow
s. This is done to facilitate
porting In software engineering Software engineering is the systematic application of engineering Engineering is the use of scientific principles to design and build machines, structures, and other items, including bridges, tunnels, roads, veh ...
of machine language programs between different models. An example of this use is the IBM
System/360 The IBM System/360 (S/360) is a family of mainframe computer A mainframe computer, informally called a mainframe or big iron, is a computer used primarily by large organizations for critical applications like bulk data processing for t ...
family of computers and their successors. With dataflow path widths of 8 bits to 64 bits and beyond, they nevertheless present a common architecture at the machine language level across the entire line. Using microcode to implement an
emulator In computing, an emulator is Computer hardware, hardware or software that enables one computer system (called the ''host'') to behave like another computer system (called the ''guest''). An emulator typically enables the host system to run so ...
enables the computer to present the architecture of an entirely different computer. The System/360 line used this to allow porting programs from earlier IBM machines to the new family of computers, e.g. an IBM 1401/1440/1460 emulator on the IBM S/360 model 40.


Relationship to bytecode

Machine code is generally different from
bytecode Bytecode, also termed portable code or p-code, is a form of instruction set In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions ...
(also known as p-code), which is either executed by an interpreter or itself compiled into machine code for faster (direct) execution. An exception is when a processor is designed to use a particular bytecode directly as its machine code, such as is the case with
Java processorA Java processor is the implementation of the Java virtual machine (JVM) in hardware. In other words, the Java bytecode that makes up the instruction set of the abstract machine becomes the instruction set of a concrete machine. These are the most ...
s. Machine code and assembly code are sometimes called ''
native Native may refer to: People * Jus soli, citizenship by right of birth * Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory ** Native Americans (disambiguation) In arts and entertain ...
code'' when referring to platform-dependent parts of language features or libraries.


Storing in memory

The
Harvard architecture The Harvard architecture is a computer architecture with separate computer storage, storage and signal pathways for Machine code, instructions and data. It contrasts with the von Neumann architecture, where program instructions and data share ...

Harvard architecture
is a computer architecture with physically separate storage and signal pathways for the code (instructions) and
data Data (; ) are individual facts A fact is something that is truth, true. The usual test for a statement of fact is verifiability—that is whether it can be demonstrated to correspond to experience. Standard reference works are often used ...
. Today, most processors implement such separate signal pathways for performance reasons but implement a
Modified Harvard architecture The modified Harvard architecture is a variation of the Harvard architecture, Harvard computer architecture that, unlike the pure Harvard architecture, allows the contents of the instruction memory to be accessed as data. Most modern computers th ...
, so they can support tasks like loading an
executable 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 computer hardware , hardware and ...
program from
disk storage Disk storage (also sometimes called drive storage) is a general category of storage mechanisms where data is recorded by various electronic, magnetic, optical, or mechanical changes to a surface layer of one or more rotating disks. A disk drive is ...
as data and then executing it. Harvard architecture is contrasted to the
Von Neumann architecture The von Neumann architecture — also known as the von Neumann model or Princeton architecture — is a computer architecture In computer engineering Computer engineering (CoE or CpE) is a branch of engineering Engineering is ...

Von Neumann architecture
, where data and code are stored in the same memory which is read by the processor allowing the computer to execute commands. From the point of view of a
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process A business process, business method ...
, the ''code space'' is the part of its
address space 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 computer hardware , hardware and softwa ...

address space
where the code in execution is stored. In multitasking systems this comprises the program's
code segment 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 computer hardware , hardware and softwar ...
and usually
shared libraries 277px, Illustration of an application which uses libvorbisfile to play an Ogg Vorbis file In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as ...
. In multi-threading environment, different threads of one process share code space along with data space, which reduces the overhead of
context switching 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 computer hardware , hardware and softwa ...
considerably as compared to process switching.


Readability by humans

Pamela Samuelson wrote that machine code is so unreadable that the
United States Copyright Office The United States Copyright Office (sometimes abbreviated USCO), a part of the Library of Congress The Library of Congress (LC) is the research library A library is a curated collection of sources of information and similar resou ...
cannot identify whether a particular encoded program is an original work of authorship; however, the US Copyright Office ''does'' allow for copyright registration of computer programs and a program's machine code can sometimes be
decompiled A decompiler is a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a programming language ...
in order to make its functioning more easily understandable to humans. However, the output of a decompiler or disassembler will be missing the comments and symbolic references, so while the output may be easier to read than the object code, it will still be more difficult than the original source code. This problem does not exist for object-code formats like
SQUOZE SQUOZE (abbreviated as SQZ) is a memory-efficient representation of a combined Source code, source and relocation (computer science), relocatable object file, object program file with a symbol table on punched cards which was introduced in 1958 wit ...
, where the source code is included in the file. Cognitive science professor
Douglas Hofstadter Douglas Richard Hofstadter (born February 15, 1945) is an American scholar of cognitive science Cognitive science is the interdisciplinary Interdisciplinarity or interdisciplinary studies involves the combination of two or more academic ...
has compared machine code to
genetic code The genetic code is the set of rules used by living cells Cell most often refers to: * Cell (biology), the functional basic unit of life Cell may also refer to: Closed spaces * Monastic cell, a small room, hut, or cave in which a monk or rel ...

genetic code
, saying that "Looking at a program written in machine language is vaguely comparable to looking at a
DNA Deoxyribonucleic acid (; DNA) is a molecule File:Pentacene on Ni(111) STM.jpg, A scanning tunneling microscopy image of pentacene molecules, which consist of linear chains of five carbon rings. A molecule is an electrically neutral gro ...

DNA
molecule atom by atom."


See also

*
Assembly language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gene ...
*
Endianness In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithm of an algorithm (Euclid's algorithm) for calculating the greatest comm ...
* List of machine languages *
Machine code monitor A machine is a man-made device that uses Power (physics), power to apply Force, forces and control Motion, movement to perform an action. Machines can be driven by Animal power, animals and Human power, people, by natural forces such as Wind pow ...
* Overhead code *
P-code machine In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, gene ...
*
Reduced instruction set computing In computer engineering Computer engineering (CoE or CpE) is a branch of engineering Engineering is the use of scientific principles to design and build machines, structures, and other items, including bridges, tunnels, roads, v ...
(RISC) *
Very long instruction word Very long instruction word (VLIW) refers to instruction set architecture In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical ...
* Teaching Machine Code: Micro-Professor MPF-I


Notes


References


Further reading

* * * {{Authority control * Low-level programming languages