Machine code

Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data (in a register or in memory, e.g. add or move), or a jump operation (deciding which instruction executes next, often conditional on the results of a previous instruction). Every executable program is made up of a series of these atomic instructions. Machine code may be regarded as a primitive (and cumbersome) programming language or as the lowest-level representation of a compiled and/or assembled computer program. While it is possible to write programs in machine code, because of the tedious difficulty in managing CPU resources, it is rarely done any more, except for situations that require the most extreme optimization.

Almost all executable programs are written in higher level languages, and translated to executable machine code by a compiler and linker. Machine code is sometimes called native code when referring to platform-dependent parts of language features or libraries.[1]

Programs in interpreted languages[2] are not represented by machine code, however, their interpreter (which may be seen as a processor executing the higher level program) often is. Machine code should not be confused with so called "bytecode", which is executed by an interpreter.


Machine code instructions

Every processor or processor family has its own machine code instruction set. Instructions are patterns of bits that by physical design correspond to different commands to the machine. The instruction set is thus specific to a class of processors using (much) the same architecture. Successor or derivative processor designs often include all the instructions of a predecessor and may add 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 nearly completely compatible processors may show slightly different behavior for some instructions but this is seldom 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 machine code instruction set may have all instructions of the same length, or it may have variable-length instructions. How the patterns are organized varies strongly with the particular architecture and often also with the type of instruction. Most instructions have one or more opcode fields which specifies the basic instruction type (such as arithmetic, logical, jump, etc.) and the actual operation (such as add or compare) and other fields that may give the type of the operand(s), the addressing mode(s), the addressing offset(s) or index, or the actual value itself (such constant operands contained in an instruction are called immediates).


A computer program is a sequence of instructions that are executed by a CPU. While simple processors execute instructions one after the other, superscalar processors are capable of executing several instructions at once.

Program flow may be influenced by special 'jump' instructions that transfer execution to an instruction other than the numerically following one. Conditional jumps are taken (execution continues at another address) or not (execution continues at the next instruction) depending on some condition.

Assembly languages

A much more readable rendition of machine language, called assembly language, uses mnemonic codes to refer to machine code instructions, rather than using the instructions' numeric values directly. For example, on the Zilog Z80 processor, the machine code 00000101, which causes the CPU to decrement the B processor register, would be represented in assembly language as DEC B.


The MIPS architecture 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
[  op  |  rs |  rt |  rd |shamt| funct]  R-type
[  op  |  rs |  rt | address/immediate]  I-type
[  op  |        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:

[  op  |  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:

[  op  |  rs |  rt | address/immediate]
   35     3     8           68           decimal
 100011 00011 01000 00000 00001 000100   binary

Jumping to the address 1024:

[  op  |        target address        ]
    2                 1024               decimal
 000010 00000 00000 00000 10000 000000   binary

Relationship to microcode

In some computer architectures, the machine code is implemented by a more fundamental underlying layer of programs called microprograms, providing a common machine language interface across a line or family of different models of computer with widely different underlying dataflows. This is done to facilitate porting of machine language programs between different models. An example of this use is the IBM System/360 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 a microcode layer to implement an emulator 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.

Storing in memory

The Harvard architecture is a computer architecture with physically separate storage and signal pathways for the code (instructions) and data. Today, most processors implement such separate signal pathways for performance reasons but actually implement a Modified Harvard architecture, so they can support tasks like loading a program from disk storage as data and then executing it. Harvard architecture is contrasted to the Von Neumann architecture, where data and code are stored in the same memory.

From the point of view of a process, the code space is the part of its address space where code in execution is stored. In multi-threading environment, threads share code space along with data space, which reduces the overhead of context switching considerably as compared to process switching.

Readability by humans

It has been said that machine code is so unreadable that the Copyright Office cannot even identify whether a particular encoded program is an original work of authorship.[3] Hofstadter writes, "Looking at a program written in machine language is vaguely comparable to looking at a DNA molecule atom by atom."[4] As with many things, there are exceptions. There are some people who do use machine code as their primary programming language and do find such code more readable than mnemonic representations.[citation needed]

See also

Further reading

  • Hennessy, John L.; Patterson, David A.. Computer Organization and Design. The Hardware/Software Interface.. Morgan Kaufmann Publishers. ISBN 1-55860-281-X. 
  • Tanenbaum, Andrew S.. Structured Computer Organization. Prentice Hall. ISBN 0-13-020435-8. 
  • Brookshear, J. Glenn. Computer Science: An Overview. Addison Wesley. ISBN 0321387015. 

Notes and references

  1. ^ "Managed, Unmanaged, Native: What Kind of Code Is This?". Retrieved 2008-09-02. 
  2. ^ Often BASIC, MATLAB, Smalltalk, Python, Ruby, etc.
  3. ^ Pamela Samuelson (Sep., 1984), CONTU Revisited: The Case against Copyright Protection for Computer Programs in Machine-Readable Form, 1984, Duke Law Journal, pp. 663–769, JSTOR 1372418 
  4. ^ D. Hofstadter, Gödel, Escher, Bach (1980), An Eternal Golden Braid, pp. 290 

Wikimedia Foundation. 2010.

Look at other dictionaries:

  • machine code — ➔ code * * * machine code UK US noun [C or U] (also machine language) IT ► the basic language used to give instructions to a computer, consisting only of numbers: »The program has been written in machine code. »Z 80 machine code is fairly easy to …   Financial and business terms

  • machine code — n. (Computers) Same as {machine language}. [WordNet 1.5] …   The Collaborative International Dictionary of English

  • machine code — (also machine language) ► NOUN ▪ a computer programming language consisting of instructions which a computer can respond to directly …   English terms dictionary

  • machine code — noun a set of instructions coded so that the computer can use it directly without further translation • Syn: ↑machine language • Hypernyms: ↑code, ↑computer code * * * maˈchine code [machine code] …   Useful english dictionary

  • machine code — UK / US noun [countable/uncountable] Word forms machine code : singular machine code plural machine codes computing a series of instructions written in a form that a computer can read and understand …   English dictionary

  • machine code — kompiuterinis kodas statusas T sritis automatika atitikmenys: angl. machine code vok. Maschinencode, m rus. машинный код, m pranc. code de machine, m; langage, m …   Automatikos terminų žodynas

  • machine code — N UNCOUNT Machine code is a way of expressing instructions and information in the form of numbers which can be understood by a computer or microchip. [TECHNICAL] …   English dictionary

  • machine code — kompiuterinė kalba statusas T sritis informatika apibrėžtis ↑Programavimo kalba, kurią tiesiogiai, be ↑interpretatoriaus, supranta kompiuteris ir vykdo ja užrašytas komandas. Tai galutinis ↑asemblerio arba transliavimo iš aukštesnio lygio… …   Enciklopedinis kompiuterijos žodynas

  • machine code — operacijos kodas statusas T sritis informatika apibrėžtis ↑Kompiuterinės komandos dalis, nurodanti, kokią operaciją turi atlikti ↑procesorius, dažniausiai užimanti vieną baitą ir užrašoma šešioliktainiu skaičiumi. atitikmenys: angl. machine code… …   Enciklopedinis kompiuterijos žodynas

  • machine code — noun see machine language …   New Collegiate Dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”