Machine Language

Download Report

Transcript Machine Language


Suppose for a moment that you were asked to perform a task
and were given the following list of instructions to perform:
0001
1101
1111
0000
0001

0011
0111
0001
1100
0011
0011
0001
1101
0101
0011
1011
1001
1111
1101
1011
Because these are the only instructions a computer
actually can understand and perform, at some point
every program a computer runs must be converted to
machine instructions.


Opcode (first few bits), say what general task
is to be done - something like “store a
number” or “add two numbers”.
Operands (the rest of the instruction) the
extra information needed to understand the
instruction - things like where to store the
number or which two numbers to add.


The figure below shows how an imaginary computer might interpret
an instruction. The first 4 bits are the opcode - in this case we are
assuming 0001 means “add two values”. The next 6 bits specify the
memory address of the first number we are adding and the last 6
bits specify the memory address of the second number.
How a computer might interpret the instruction
0001110001001011.


Computers usually support only a small
number of machine code instructions; a few
dozen to a few hundred very simple
instructions like “add two numbers” or “store
a value to memory”.
The list of available instruction and the
format for specifying them make up a
machine language.


a human readable direct translation of
machine language
instead of writing “0100001101” to say “store
the current value to memory location 13” in
machine language, in assembly you could
write something like “STORE 13”.
Although assembly is much easier to read than machine code, you
probably noticed that it is still very low level. A job as simple as “add 2
and 5” took many instructions to express. For this reason, most
programmers do not work in assembly most of the time.




invented to abstract away the details of machine code and
help programmers to concentrate on problem solving
C++, Java or Python (FORTRAN one of first)
Programs written in a high level languages must be converted
into machine code to run.
This is either done ahead of time by converting a whole
program to machine code with a compiler program (compiling
the code), or line by line as the program runs by an
interpreter


add two values that are stored in the main
memory and place the sum back in the main
memory.
Suppose 02 and 08 are the values of the
bytes stored in the main memory cells with
addresses F0 and F1

1.
2.
3.
4.
5.
English words to describe instructions
Load the value of the memory cell with address F0 into
register 0.
Load the value of the memory cell with address F1 into
register 1.
Add the values in register 0 and register 1 and place the
result in register 2.
Store the value of register 2 into the memory cell with
address F2.
Halt execution
1
2
3
4
5
6
7
RXY
RXY
RXY
0RS
RST
RST
RST
8 RST
9 RST
A R0X
B RXY
C 000
D RXY
E
0RS
LOAD bit pattern found in memory cell XY into register R.
LOAD the bit pattern XY into register with address R.
STORE the bit pattern found in the register R in memory cell XY.
MOVE (copy) bit pattern from register R to register S.
ADD integers in registers S and T (two’s complement form) and place result in register R.
ADD floating-point numbers in registers S and T and place result in register R.
Combine bit pattern in register S and register T using the OR operator and place result in
register R.
Combine bit pattern in register S and register T using the AND operator and place result in
register R.
Combine bit pattern in register S and register T using the EXCLUSIVE OR operator and place
result in register R.
ROTATE bit pattern in register R to the right X times.
JUMP to instruction located in memory cell XY IF the bit pattern in register R is EQUAL to bit
pattern in register 0; otherwise continue to next instruction.
HALT the program’s execution.
JUMP to instruction XY IF the bit pattern in register R is LESS THAN ZERO; otherwise
continue to next instruction.
NOT—negate each bit in pattern found in register S and put resulting bit pattern in register
R.
1.
2.
3.
4.
5.
Load the value of the memory cell with 10F0
11F1
5201
address F0 into register 0. (10F0)
32F2
Load the value of the memory cell with C000
address F1 into register 1. (11F1)
Add the values in register 0 and register 1
and place the result in register 2. (5201)
Store the value of register 2 into the
memory cell with address F2. (32F2)
Halt Execution (C000)
10F0
11F1
5201
32F2
C000
Load the value of the memory cell with address
F0 into register 0.
10F0
11F1
5201
32F2
C000
Load the value of the memory cell with address F1 into
register 1.
10F0
11F1
5201
32F2
C000
Add the values in register 0 and register 1 and place
the result in register 2.
10F0
11F1
5201
32F2
C000
Store the value of register 2 into the
memory cell with address F2.
10F0
11F1
5201
32F2
C000
Halt execution
10F0
11F1
5201
32F2
C000

General Purpose Registers: these components are general use memory storage in the CPU that

Special Purpose Registers: these components are dedicated memory storage in the CPU that

Buses: these components are the information highway for the CPU. Buses are bundles of tiny

ALU: this component is the number cruncher of the CPU. The Arithmetic / Logic Unit performs

Control Unit: this component is responsible for directing the flow of instructions and data
can be accessed very fast (as compared to RAM); they are created from combining latches with
a decoder. The latches create circuitry that can remember while the decoder creates a way for
individual memory locations to be selected.
can be accessed very fast. Three SP registers are shown: the Instruction Register (IR), the
Program Counter (PC), and the Accumulator.
wires that carry data between components. The three most important buses are the address,
the data, and the control buses.
all the mathematical calculations of the CPU. It is composed of complex circuitry similar to the
adder presented in the previous lesson. The ALU, however, can add, subtract, multiply, divide,
and perform a host of other calculations on binary numbers.
within the CPU. The Control Unit is actually built of many other selection circuits such as
decoders and multiplexors. In the diagram above, the Decoder and the Multiplexor compose
the Control Unit.