Professional Documents
Culture Documents
1 CPU Architecture
in
M
-M
us
ht
a
us
sa
in
sa
us
H
System clock
us
ht
a
Every computer contains an internal clock that regulates the rate at which instructions are
executed and synchronizes all the various computer components. The CPU requires a fixed
number of clock ticks (or clock cycles) to execute each instruction. The faster the clock, the
more instructions the CPU can execute per second.
Clock speeds are expressed in mega hertz (MHz) or giga hertz ((GHz).
M
-M
Control bus
Control bus is used to send control signals from the control unit to the other components of
the system. A separate wire is dedicated to a particular control signal e.g.
A completed data transfer(read/write)operation
Reset button pressed
Interrupt request
Interrupt acknowledgement
How bus width and clock speed affect the performance of the computer system
us
Increasing the data bus will increase the quantity of data the bus can carry at one
time so speeds up the performance/processing of the computer
M
-M
ht
a
us
sa
in
The clock speed (or clock rate) is stated in megahertz (MHz) or gigahertz (GHz), and
refers to the speed at which the processor can execute instructions. The faster the
clock, the more instructions the processor can complete per second.
The number of wires in data bus determines the quantity of data that the bus can
carry at any one time.
A compute with a data bus of 32 lines is called a 32 bit computer and word length is
32.
Ports:
in
sa
us
H
q
ht
a
us
M
-M
Program counter (PC) - an incrementing counter that keeps track of the memory
address of the instruction that is to be executed next.
Memory address register (MAR) - holds the address of a memory block to be read
from or written to.
Memory data register (MDR) - a two-way register that holds data fetched from
memory (and ready for the CPU to process) or data waiting to be stored in memory.
Current Instruction register (IR) - a temporary holding ground for the instruction
in
Control unit (CU) - decodes the program instruction in the IR, selecting machine
sa
us
ht
a
M
-M
us
resources such as a data source register and a particular arithmetic operation, and
M
-M
us
ht
a
us
sa
in
1. [MAR] [PC]
2. PC [PC] + 1
3. MDR [[MAR]]
4. CIR [MDR]
5. DECODE
6. EXECUTE
7. GO TO STEP 1
us
sa
in
M
-M
us
ht
a
After increment
M
-M
us
ht
a
us
sa
in
4. The MBR loads the Current Instruction Register with the instruction to be executed.
M
-M
us
ht
a
us
sa
in
us
sa
in
Op code (abbreviated from operation code) is the portion of a machine language instruction
that specifies the operation to be performed
Operand address or data on which the operation is to be performed.
q
ht
a
Immediate
Direct
Indirect
Indexed
Relative
us
Addressing modes
M
-M
Immediate addressing
Immediate addressing means that the data to be used is hard-coded into the instruction
itself.This is the fastest method of addressing as it does not involve main memory at all.
For example, you want to add 2 to the content of the accumulator
The instruction is:
ADD #2
Nothing has been fetched from memory; the instruction simply adds 2 to the accumulator
immediately. Immediate Addressing is very useful to carry out instructions involving
constants (as opposed to variables). For example you might want to use 'PI' as a constant
3.14 within your code.
Direct addressing
This is a very simple way of addressing memory - direct addressing means the code refers
directly to a location in memory
For example SUB (3001)
In this instance the value held at the absolute location 3001 in RAM is subtracted from the
accumulator. The good thing about direct addressing is that it is fast (but not as fast as
immediate addressing) the bad thing about direct addressing is that the code depends on
the correct data always being present at same location.
It is generally a good idea to avoid referring to absolute memory addresses in order to have
'relocatable code' i.e. code that does not depend on specific locations in memory.
M
-M
us
ht
a
us
sa
in
You could use direct addressing on computers that are only running a single program. For
example an engine management computer only ever runs the code the car engineers
programmed into it, and so direct memory addressing is excellent for fast memory access.
M
-M
us
ht
a
us
sa
in
Indirect addressing
Indexed addressing
The address is formed by the operand plus the number in the index register.
CIR
ADI
10
IR(index register)
10
.
.
150
.
160
.
.
200
accumulator
120
200
120
395
us
sa
in
Index addressing is fast and is excellent for manipulating data structures such as arrays as
all you need to do is set up a base address (e.g. 10 in CIR) then use the index in your code
to access individual elements. Another advantage of indexed addressing is that if the array
is re-located in memory at any point then only the base address needs to be changed. The
code making use of the index can remain exactly the same.
Relative addressing
M
-M
DEFINITION:
us
ht
a
Quite often a program only needs to jump a little bit in order to jump to the next
instruction. Maybe just a few memory locations away from the current instruction. A very
efficient way of doing this is to just add a small offset to the current address in the program
counter. (Remember that the program counter always points to the next instruction to be
executed).This is called 'relative addressing'
Relative addressing means that the next instruction to be carried out is an offset number of
locations away, relative to the address of the current instruction.
Consider this bit of pseudo-code:
jmp +3 if accumulator == 2
Code executed if accumulator is NOT = 2
jmp +5 (unconditional relative jump to avoid the next line of code)
acc:
Code executed if accumulator is = 2)
Carry on:
In the code snippet above, the first line of code is checking to see if the accumulator has the
value of 2 in it. If it is has, then the next instruction is 3 lines away. This is called a
conditional jump and it is making use of relative addressing.
Another example of relative addressing can be seen in the jmp +5 instructions. This is
telling the CPU to effectively avoid the next instruction and go straight to the 'carryon' point.
us
sa
in
M
-M
us
ht
a
M
-M
us
ht
a
us
sa
in
Assembly language