Presentation on theme: " Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform: 0001 0011 0011 1011 1101 0111."— Presentation transcript:
Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform: 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
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 “ ” 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
English words to describe instructions 1. Load the value of the memory cell with address F0 into register Load the value of the memory cell with address F1 into register Add the values in register 0 and register 1 and place the result in register Store the value of register 2 into the memory cell with address F2. 5. Halt execution
1 RXY LOAD bit pattern found in memory cell XY into register R. 2 RXY LOAD the bit pattern XY into register with address R. 3 RXY STORE the bit pattern found in the register R in memory cell XY. 4 0RS MOVE (copy) bit pattern from register R to register S. 5 RST ADD integers in registers S and T (two’s complement form) and place result in register R. 6 RST ADD floating-point numbers in registers S and T and place result in register R. 7 RST Combine bit pattern in register S and register T using the OR operator and place result in register R. 8 RST Combine bit pattern in register S and register T using the AND operator and place result in register R. 9 RST Combine bit pattern in register S and register T using the EXCLUSIVE OR operator and place result in register R. A R0X ROTATE bit pattern in register R to the right X times. B RXY 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. C 000 HALT the program’s execution. D RXY JUMP to instruction XY IF the bit pattern in register R is LESS THAN ZERO; otherwise continue to next instruction. E 0RS NOT—negate each bit in pattern found in register S and put resulting bit pattern in register R.
1. Load the value of the memory cell with address F0 into register 0. (10F0) 2. Load the value of the memory cell with address F1 into register 1. (11F1) 3. Add the values in register 0 and register 1 and place the result in register 2. (5201) 4. Store the value of register 2 into the memory cell with address F2. (32F2) 5. Halt Execution (C000) 10F0 11F F2 C000
10F0 11F F2 C000
10F0 11F F2 C000 Load the value of the memory cell with address F0 into register 0.
10F0 11F F2 C000 Load the value of the memory cell with address F1 into register 1.
10F0 11F F2 C000 Add the values in register 0 and register 1 and place the result in register 2.
10F0 11F F2 C000 Store the value of register 2 into the memory cell with address F2.
10F0 11F F2 C000 Halt execution
General Purpose Registers: these components are general use memory storage in the CPU that 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. Special Purpose Registers: these components are dedicated memory storage in the CPU that can be accessed very fast. Three SP registers are shown: the Instruction Register (IR), the Program Counter (PC), and the Accumulator. Buses: these components are the information highway for the CPU. Buses are bundles of tiny wires that carry data between components. The three most important buses are the address, the data, and the control buses. ALU: this component is the number cruncher of the CPU. The Arithmetic / Logic Unit performs 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. Control Unit: this component is responsible for directing the flow of instructions and data 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.