From Wikipedia, the free encyclopedia
Machine code instructions
The "words" of a machine. Instructions are patterns of bits with different patterns corresponding to different commands to the machine.
Every CPU model does not have its own machine code, or instruction set, although there is considerable overlap between some. If CPU A understands the full language of CPU B it is said that A is compatible with B. CPU B may not be compatible with CPU A, as A may know a few codes that B does not.
Some machine languages give all their instructions the same number of bits, while the instruction length differs in others. How the patterns are organised depends largely on the specification of the machine code. Common to most is the division of one field (the opcode) which specifies the exact operation (for example "add"). Other fields may give the type of the operands, their location, or their value directly (operands contained in an instruction are called immediate). Some exotic instruction sets do not have an opcode field (such as Transport Triggered Architectures or the Forth virtual machine), only operand(s). Other instruction sets lack any operand fields, such as NOSCs".
A 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 following one. Conditional jumps are taken (execution continues at another address) or not (execution continues at the next instruction) depending on some condition.
Humans use mnemonic codes to refer to machine code instructions. Such a more readable rendition of the machine language is called an assembly language and consists of both binary numbers and simple words whereas machine code is composed only of the two binary digits 0 and 1.
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
Loading a value from the memory cell 68 cells after the one register 3 points to into register 8:
[ op | rs | rt | address/immediate] 35 3 8 68 decimal 100011 00011 01000 00000 00001 000100 binary
Jumping to the address 1025:
[ op | target address ] 2 1025 decimal 000010 00000 00000 00000 10000 000001 binary
Are machine languages special?
There is on occasion among programmers a tendency to see machine language as exceptional or basic. As a matter of fact, a machine language is in no sense more fundamental than any other language in which programs are described. Rather, machine language is a consequence of the necessity of simple elements in the electrical design of computers. Indeed, machine language programs are among the most difficult kinds of programs for a human being to read and modify, and, although familiarity with machine language will allow able programmers to compensate for the deficiencies of automatic code generation by compilers or interpreters, it will not simplify the job.
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.