All Topics  
Machine code

 

   Email Print
   Bookmark   Link






 

Machine code



 
 
Machine code or machine language is a system of instructions and data executed directly by a computer
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
's central processing unit
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
. Machine code may be regarded as a primitive (and cumbersome) programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 or as the lowest-level representation of a compiled and/or assembled
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
 computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
. Programs in interpreted language
Interpreted language

In computer programming an interpreted language is a programming language whose implementation often takes the form of an interpreter . Theoretically, any language may be compiler or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language....
s are not represented by machine code however, although their interpreter (which may be seen as a processor executing the higher level program) often is.






Discussion
Ask a question about 'Machine code'
Start a new discussion about 'Machine code'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Machine code or machine language is a system of instructions and data executed directly by a computer
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
's central processing unit
Central processing unit

A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage....
. Machine code may be regarded as a primitive (and cumbersome) programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 or as the lowest-level representation of a compiled and/or assembled
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
 computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
. Programs in interpreted language
Interpreted language

In computer programming an interpreted language is a programming language whose implementation often takes the form of an interpreter . Theoretically, any language may be compiler or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language....
s are not represented by machine code however, although their interpreter (which may be seen as a processor executing the higher level program) often is. Machine code is sometimes called native code when referring to platform-dependent parts of language features or libraries. Machine code should not be confused with so called "bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
", which is executed by an interpreter.

Machine code instructions

Instructions are patterns of bit
Bit

A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory....
s with different patterns corresponding to different commands to the machine.

Every CPU model has its own machine code, or instruction set
Instruction set

An instruction set is a list of all the instruction , and all their variations, that a processor can execute.Instructions include:* Arithmetic such as add and subtract...
. Successor or derivative processor designs may completely include all the instructions of a predecessor and may add additional instructions. Some nearly completely compatible processor designs may have slightly different effects after similar instructions. Occasionally a successor processor design will discontinue or alter the meaning of a predecessor's instruction code, making migration of machine code between the two processors more difficult. Even if the same model of processor is used, two different systems may not run the same example of machine code if they differ in memory arrangement, operating system, or peripheral devices because the machine code has no embedded information about the configuration of the system.

A machine code instruction set may have all instructions of the same length, or may have variable-length instructions. How the patterns are organized depends largely on the specification of the machine code. Common to most is the division of one field (the opcode
Opcode

In computer technology, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question ....
) which specifies the exact operation (for example "add"). Other fields may give the type of the operand
Operand

An operand is one of the inputs of an operator in mathematics. The following arithmetic expression shows an example of operators and operands:...
s, their location
Addressing mode

Addressing modes are an aspect of the instruction set architecture in most central processing unit designs. The various addressing modes that are defined in a given instruction set architecture define how Machine code Instruction in that architecture identify the operand of each instruction....
, or their value directly (operands contained in an instruction are called immediate).

Programs

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

A superscalar Central processing unit architecture implements a form of parallel computer called instruction level parallelism within a single processor....
 processors are capable of executing several instructions at once.

Program flow may be influenced by special 'jump' instructions
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
 that transfer execution to an instruction other than the 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
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
, uses mnemonic code
Mnemonic

A mnemonic device is a memory aid. Commonly met mnemonics are often verbal, something such as a very short poem or a special word used to help a person remember something, particularly lists, but may be visual, kinesthetic or auditory....
s to refer to machine code instructions, rather than simply using the instructions' numeric values. For example, on the Zilog Z80
Zilog Z80

The Zilog Z80 is an 8-bit microprocessor designed and sold by Zilog from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes....
 processor, the machine code 00000101, which causes the CPU to decrement the B processor register
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
, would be represented in assembly language as DEC B.

Example

The MIPS architecture
MIPS architecture

MIPS is a RISC instruction set architecture developed by MIPS Technologies . In the mid to late 1990s, it was estimated that one in three RISC microprocessors produced were MIPS implementations....
 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 00100 000000 binary

Relationship to microcode

In some computer architecture
Computer architecture

Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an...
s, 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 dataflow
Dataflow

Dataflow is a term used in computing, and may have various shades of meaning. It is closely related to message passing....
s. This is done to facilitate porting
Porting

In computer science, porting is the process of adapting software so that an executable Computer program can be created for a computing environment that is different from the one for which it was originally designed ....
 of machine language programs between different models. An example of this use is the IBM System/360
System/360

The IBM System/360 is a mainframe computer system family announced by IBM on April 7, 1964. It was the first family of computers making a clear distinction between computer architecture and implementation, allowing IBM to release a suite of compatible designs at different price points....
 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
Emulator

An emulator duplicates the functions of one system using a different system, so that the second system behaves like the first system. This focus on exact reproduction of external behavior is in contrast to some other forms of computer simulation, which can concern an abstract model of the system being simulated....
 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
IBM 1400 series

The IBM 1400 series were second generation mid-range business computers that IBM sold in the early 1960s. They could be operated as an independent systems, in conjunction with IBM punched card equipment, or as auxiliary equipment to other computer systems....
 emulator on the IBM S/360 model 40.

See also

  • Reduced Instruction Set Computer
    Reduced instruction set computer

    The acronym RISC , for reduced instruction set computing, represents a CPU design strategy emphasizing the insight that simplified instructions that "do less" may still provide for higher performance if this simplicity can be utilized to make instructions execute very quickly....
     (RISC)
  • VLIW
  • P-code
    P-Code machine

    In computer programming, a p-code machine or pseudo-code machine is a virtual machine designed to execute p-code . This term is applied both generically to all such machines , and to specific implementations, the most famous being the p-Machine of UCSD Pascal....
  • Endianness
    Endianness

    In computing, endianness is the byte ordering used to represent some kind of data. Typical cases are the order in which integer values are stored as bytes in computer memory and the transmission order over a network or other medium....
  • Teaching Machine Code: Microprofessor I


Further reading