Machine code -

Machine code

Machine code is a computer program written in machine language. It uses the instruction set of a particular computer architecture.[1] It is usually written in binary.[2][3][4][5] Machine code is the lowest level of software. Other programming languages are translated into machine code so the computer can execute them.

An instruction tells the process what operation to perform. Each instruction is made up of an opcode (operation code) and operand(s). The operands are usually memory addresses or data. An instruction set is a list of the opcodes available for a computer. Machine code is what assembly code and other programming languages are compiled to or interpreted as.

Program builders turn code into another language or machine code. Machine code is sometimes called native code. This is used when talking about things that work on only some computers.[6]


Writing machine code

Machine code can be written in different forms:

Typical instructions of machine code

There are many kinds of instructions found usually found in an instruction set:

Many modern processors use microcode for some of the commands. More complex commands tend to use it. This is often done with CISC architectures.


Every processor or processor family has its own instruction set. Instructions are patterns of bits that correspond to different commands that can be given to the machine. Thus, the instruction set is specific to a class of processors using (mostly) the same architecture.

Newer processor designs often include all the instructions of a predecessor and may add additional instructions. Sometimes, a newer design will discontinue or alter the meaning of an instruction code (typically because it is needed for new purposes), affecting code compatibility; even nearly completely 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.

Most instructions have one or more opcode fields. They specify the basic instruction type. Other fields may give the type of the operands, the addressing mode, and so on. There may also be special instructions that are contained in the opcode itself. These instructions are called immediates.

Processor designs can be different in other ways. Different instructions can have different lengths. Also, they can have the same length. Having all instructions have the same length can simplify the design.


The MIPS architecture has instructions which are 32 bits long. This section has examples of code. The general type of instruction is in the op (operation) field. It is the highest 6 bits. J-type (jump) and I-type (immediate) instructions are fully given by op. R-type (register) instructions include the field funct. It determines the exact operation of the code. 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. The address or immediate fields contain an operand directly.

Example: add the registers 1 and 2. Place the result in register 6. It 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. Take it 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

Jump to the address 1024:

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

Related pages


  1. "What is machine language?" . Webopedia. Retrieved 2010-4-24. Check date values in: |accessdate= (help)
  2. "What is Machine Code?" . Wise Geek. Retrieved 2010-04-23.
  3. "What is machine code" . Retrieved 2010-04-23.
  4. "Machine language - Definition and More from the Free Merriam-Webster Dictionary" . Merriam-Webster. Retrieved 2010-4-24. Check date values in: |accessdate= (help)
  5. "Machine language" . Computer Hope. Retrieved 2010-4-24. Check date values in: |accessdate= (help)
  6. "Managed, Unmanaged, Native: What Kind of Code Is This?" . Retrieved 2008-09-02.

Categories: Computer science

Information as of: 28.10.2020 07:16:38 CET

Source: Wikipedia (Authors [History])    License : CC-by-sa-3.0

Changes: All pictures and most design elements which are related to those, were removed. Some Icons were replaced by FontAwesome-Icons. Some templates were removed (like “article needs expansion) or assigned (like “hatnotes”). CSS classes were either removed or harmonized.
Wikipedia specific links which do not lead to an article or category (like “Redlinks”, “links to the edit page”, “links to portals”) were removed. Every external link has an additional FontAwesome-Icon. Beside some small changes of design, media-container, maps, navigation-boxes, spoken versions and Geo-microformats were removed.

Please note: Because the given content is automatically taken from Wikipedia at the given point of time, a manual verification was and is not possible. Therefore does not guarantee the accuracy and actuality of the acquired content. If there is an Information which is wrong at the moment or has an inaccurate display please feel free to contact us: email.
See also: Legal Notice & Privacy policy.