Lect02 1 SmallComp-1 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

A SIMPLE COMPUTER

To explain the architecture of computers as well as


their instruction processing, we introduce a simple
(unrealistic) computer, as shown in next Figure.

Our simple computer has three components: CPU,


main memory and an input/output subsystem.
Figure: The components of a simple computer
Instruction set

Each computer instruction consists of two parts: the operation code


(opcode) and the operand (s).

The opcode specifies the type of operation to be performed on the


operand (s).

Each instruction consists of sixteen bits divided into four 4-bit fields.

The leftmost field contains the opcode and the other three fields
contains the operand or address of operand (s), as shown in next
Figure.

opcode oprand
Figure: Format and different instruction types

R-address: address of a register


Memory address: Main memory address
Processing the instructions
Our simple computer, like most computers, uses machine cycles.

A cycle is made of three phases: fetch, decode and execute.

During the fetch phase, the instruction whose address is in PC is


obtained from the memory and loaded into the IR. The PC is then
incremented to point to the next instruction.

During the decode phase, the instruction in IR is decoded and the


required operands are fetched from the register or from memory.

During the execute phase, the instruction is executed and the results
are placed in the appropriate memory location or the register.

Once the third phase is completed, the control unit starts the cycle
again, but now the PC is pointing to the next instruction. The process
continues until the CPU reaches a HALT instruction.
An example
Let us show how our simple computer can add two
integers A and B and create the result as C.

We assume that integers are in two’s complement


format. Mathematically, we show this operation as:

We assume that the first two integers are stored in


memory locations (40)16 and (41)16 and
the result should be stored in memory location (42)16.

To do the simple addition needs five instructions, as


shown next:
In the language of our simple computer, these five
instructions are encoded as:

5.8
Storing program and data
We can store the five-line program in memory starting from
location (00)16 to (04)16.

We already know that the data needs to be stored in memory


locations (40)16, (41)16, and (42)16.

Cycles
Our computer uses one cycle per instruction. If we have a small
program with five instructions, we need five cycles. We also
know that each cycle is normally made up of three steps: fetch,
decode, execute.

Assume for the moment that we need to add 161 + 254 = 415.
The numbers are shown in memory in hexadecimal as, (00A1)16,
(00FE)16, and (019F)16.
Figure Status of cycle 1
Figure Status of cycle 2
Figure: Status of cycle 3
Figure: Status of cycle 4
Figure: Status of cycle 5

You might also like