04 Processor Fundamentals
04 Processor Fundamentals
4.1
In this chapter, you will learn about
the basic Von Neumann model of a computer system
107
108
4.1
» a central processing unit (CPU or processor)
» a processor able to access the memory directly
memory address
register (MAR)
system
clock
accumulator
ARITHMETIC AND (ACC)
LOGIC UNIT (ALU) status registers
(SR) CPU
109
4
calculations.
System clock
A system clock is used to produce timing signals on the control bus to ensure
this vital synchronisation takes place – without the clock the computer would
simply crash. (See Section 4.1.4 System buses.)
4.1.3 Registers
One of the most fundamental components of the Von Neumann system is the
register. Registers can be general purpose or special purpose. General purpose
registers hold data that is frequently used by the CPU or can be used by the
programmer when addressing the CPU directly. The accumulator is a good
example of a general purpose register and will be used as such throughout this
book. Special purpose registers have a specific function within the CPU and
hold the program state.
The most common special registers referred to in this book are shown in
Table 4.1. The use of many of these registers is explained more fully in
Section 4.1.6 (fetch-execute cycle) and in Section 4.2 (tracing of assembly
code programs).
Register Abbreviation Function/purpose of register
current instruction CIR stores the current instruction being decoded and
register executed
index register IX used when carrying out index addressing
operations (assembly code)
memory address MAR stores the address of the memory location
register currently being read from or written to
memory data/ MDR/MBR stores data which has just been read from memory
buffer register or data which is about to be written to memory
(sometimes referred to as MBR)
program counter PC stores the address where the next instruction to be
read can be found
status register SR contain bits which can be set or cleared depending
on the operation (for example, to indicate overflow
in a calculation)
▲ Table 4.1 Common registers
110
4
used in the fetch-execute cycle, which is covered later in this chapter.
Index registers are best explained when looking at addressing techniques in
assembly code (again, this is covered later in the chapter).
A status register is used when an instruction requires some form of arithmetic
or logic processing. Each bit is known as a flag. Most systems have the
following four flags.
» Carry flag (C) is set to 1 if there is a CARRY following an addition operation
4.1
(refer to Chapter 1).
» Negative flag (N) is set to 1 if the result of a calculation yields a NEGATIVE
Since we have two positive numbers being added, the answer should not be
negative. The flags indicate two errors: a negative result, and an overflow
occurred.
Now consider this operation:
10001000 Flags:
+ 11000111 NVCZ
101001111 0110
Since we have two negative numbers being added, the answer should be
negative. The flags indicate that two errors have occurred: a carry has been
generated, and a ninth bit overflow has occurred.
Other flags can be generated, such as a parity flag, an interrupt flag or a half-
carry flag.
EXTENSION ACTIVITY 4A
Find out what conditions could cause:
a) a parity flag (P) being set to 1
b) an interrupt flag (I) being set to 1
c) a zero flag (Z) being set to 1
d) a half-carry flag (H) being set to 1.
111
ports
control bus
4 Processor fundamentals
address bus
data bus
system bus
Address bus
As the name suggests, the address bus carries addresses throughout
the computer system. Between the CPU and memory the address bus is
unidirectional (in other words, bits can travel in one direction only). This
prevents addresses being carried back to the CPU, which would be undesirable.
The width of a bus is important. The wider the bus, the more memory locations
which can be directly addressed at any given time; for example, a bus of width
16 bits can address 216 (65 536) memory locations, whereas a bus width of
32 bits allows 4 294 967 296 memory locations to be simultaneously addressed.
Even this is not large enough for modern computers, but the technology behind
even wider buses is outside the scope of this book.
Data bus
The data bus is bidirectional (in other words, it allows data to be sent in both
directions along the bus). This means data can be carried from CPU to memory
(and vice versa) as well as to and from input/output devices. It is important
to point out that data can be an address, an instruction or a numerical value.
As with the address bus, the width of the data bus is important: the wider the
bus, the larger the word length that can be transported. (A word is a group of
bits which can be regarded as a single unit, for example, 16-bit, 32-bit or
64-bit word lengths are the most common). Larger word lengths can improve
the computer’s overall performance.
Control bus
The control bus is also bidirectional. It carries signals from the CU to all the
other computer components. It is usually 8-bits wide since it only carries
control signals.
112
4
the clock cycle which synchronises all computer operations. As mentioned
earlier, the control bus transmits timing signals, ensuring everything is fully
synchronised. By increasing clock speed, the processing speed of the computer
is also increased (a typical current value is 3.5 GHz – which means 3.5 billion
clock cycles a second). Although the speed of the computer may have been
increased, it is not possible to say that a computer’s overall performance is
necessarily increased by using a higher clock speed. Four other factors need to
be considered.
4.1
1 Width of the address bus and data bus can affect computer performance.
2 Overclocking: the clock speed can be changed by accessing the basic
▲ Figure 4.3 Two cores, one channel (left) and four cores, six channels (right)
All of these factors need to be taken into account when considering computer
performance.
113
4 » increasing bus width (data and address buses) increases the performance
and speed of a computer system
» increasing clock speed usually increases the speed of a computer
» a computer’s performance can be changed by altering bus width, clock speed
and use of multi-core CPUs
» use of cache memories can also speed up a processor’s performance.
Input and output devices are connected to a computer via ports. The
interaction of the ports with connected input and output is controlled by the
control unit. Here we will summarise some of the more common types of ports
found on modern computers.
▲ Figure 4.4 (from left to right) USB cable, HDMI cable, VGA cable
USB ports
The Universal Serial Bus (USB) is an asynchronous serial data transmission
method. It has quickly become the standard method for transferring data
between a computer and a number of devices.
The USB cable consists of a four-wired shielded cable, with two wires for power
and the earth, and two wires used for data transmission. When a device is
plugged into a computer using one of the USB ports
» the computer automatically detects that a device is present (this is due
to a small change in the voltage level on the data signal wires in the
cable)
» the device is automatically recognised, and the appropriate device
driver is loaded up so that computer and device can communicate
effectively
» if a new device is detected, the computer will look for the device driver
which matches the device. If this is not available, the user is prompted to
download the appropriate software.
114
4
cons to using this system, as summarised in Table 4.2.
Pros of USB system Cons of USB system
n devices plugged into the computer n the present transmission rate is limited
are automatically detected and device to less than 500 megabits per second
drivers are automatically loaded up n the maximum cable length is presently
n the connectors can only fit one way, about five metres
which prevents incorrect connections n the older USB standard (such as 1.1)
being made may not be supported in the near future
4.1
n this has become the industry standard,
which means that considerable support
This means that modern HD televisions require more data, which has to be
received at a much faster rate than with older televisions (around 10 gigabits
per second). HDMI increases the bandwidth, making it possible to supply the
necessary data for high quality sound and visual effects.
HDMI can also afford some protection against piracy since it uses
high-bandwidth digital copy protection (HDCP). HDCP uses a type of
authentication protocol (see Chapters 6 and 17). For example, a Blu-ray player
will check the authentication key of the device it is sending data to (such as an
HD television). If the key can be authenticated, then handshaking takes place
and the Blu-ray can start to transmit data to the connected device.
115
4
phased out.
Table 4.3 summarises the pros and cons of HDMI and VGA.
Pros of HDMI Cons of HDMI
n the current standard for modern n not a very robust connection (easy to
televisions and monitors break connection when simply moving
n allows for a very fast data transfer rate device)
n improved security (helps prevent piracy) n limited cable length to retain good
4 Processor fundamentals
Fetch
The next instruction is fetched from the memory address currently stored in the
program counter (PC) and is then stored in the current instruction register
(CIR). The PC is then incremented (increased by 1) so that the next instruction
can be processed. This is decoded so that each instruction can be interpreted
in the next part of the cycle.
Execute
The processor passes the decoded instruction as a set of control signals to
the appropriate components within the computer system. This allows each
instruction to be carried out in its logical sequence.
Figure 4.5 shows how the fetch-execute cycle is carried out in the Von
Neumann computer model.
116
4
any no
instructions?
yes
4.1
location of the next instruction which has to be fetched
yes any no
interrupts to
service?
▲ Figure 4.5 How the fetch-execute cycle is carried out in the Von Neumann computer model
Double brackets are used in the third line because it is not MAR contents being
copied into MDR but it is the data stored at the address shown in MAR that is
being copied to MDR.
Compare the above instructions to those shown in Figure 4.5. Inspection should
show the register transfer notation is carrying out the same function.
117
4
(specific to a particular machine – example shown below). For example, on a
RISC computer:
4.1
» user interaction (the user pressed a key to interrupt the current process,
such as <CTRL><ALT><BREAK>, for example)
Once the interrupt signal is received, the processor either carries on with
what it was doing or stops to service the device/program that generated the
interrupt. The computer needs to identify the interrupt type and also establish
the level of interrupt priority.
Interrupts allow computers to carry out many tasks or to have several windows
open at the same time. An example would be downloading a file from the
internet at the same time as listening to some music from the computer library.
Whenever an interrupt is serviced, the status of the current task being run is
saved. The contents of the program counter and other registers are saved. Then,
the interrupt service routine (ISR) is executed by loading the start address
into the program counter. Once the interrupt has been fully serviced, the status
of the interrupted task is reinstated (contents of saved registers retrieved) and
it continues from the point prior to the interrupt being sent.
ACTIVITY 4A
1 a) Describe the functions of the following registers.
i) Current instruction register
ii) Memory address register
iii) Program counter
b) Status registers contain flags. Three such flags are named N, C and V.
i) What does each of the three flags represent?
ii) Give an example of the use of each of the three flags.
2 a) Name three buses used in the Von Neumann architecture.
b) Describe the function of each named bus.
c) Describe how bus width and clock speed can affect computer
performance.
119
4 HDMI or VGA.
Type of port Feature
analogue interface
HDMI
digital interface
120
Key terms
Machine code – the programming language that the Absolute addressing – mode of addressing in which
CPU uses. the contents of the memory location in the operand are
Instruction – a single operation performed by a CPU. used.
Assembly language – a low-level chip/machine specific Direct addressing – mode of addressing in which the
programming language that uses mnemonics. contents of the memory location in the operand are
used, which is the same as absolute addressing.
Opcode – short for operation code, the part of a
machine code instruction that identifies the action the Indirect addressing – mode of addressing in which the
CPU will perform. contents of the contents of the memory location in the
operand are used.
Operand – the part of a machine code instruction that
identifies the data to be used by the CPU. Indexed addressing – mode of addressing in which the
contents of the memory location found by adding the
Source code – a computer program before translation
contents of the index register (IR) to the address of the
into machine code.
memory location in the operand are used.
Assembler – a computer program that translates
Immediate addressing – mode of addressing in which
programming code written in assembly language into
the value of the operand only is used.
machine code. Assemblers can be one pass or two pass.
Relative addressing – mode of addressing in which the
Instruction set – the complete set of machine code
memory address used is the current memory address
instructions used by a CPU.
added to the operand.
Object code – a computer program after translation into
Symbolic addressing – mode of addressing used in
machine code.
assembly language programming, where a label is used
Addressing modes – different methods of using instead of a value.
the operand part of a machine code instruction as a
memory address.
121
4
consuming and often error prone, as the only way to test a program written
in machine code is to run it and see what happens. In order to shorten
the development time for writing computer programs, other programming
languages were developed, where the instructions were easier to learn
and understand. Any program not written in machine code needs to be
translated before the CPU can carry out the instructions, so language
translators were developed.
The first programming language to be developed was assembly language, this
4 Processor fundamentals
The structure of assembly language and machine code instructions is the same.
Each instruction has an opcode that identifies the operation to be carried out
by the CPU. Most instructions also have an operand that identifies the data to
be used by the opcode.
Opcode
Opcode Operand Operand
LDD Total 0140
Assembly language mnemonics Machine code hexadecimal
122
Pass 2
The second pass is required as some labels may be referred to before their
address is known. For example, Found is a forward reference for the JPN
instruction.
Label Opcode Operand
Notfound: LDD 200
CMP #0
JPN Found
JPE Notfound
Found: OUT
123
4 Opcode
LDM
LDD
Operand
#n
<address>
Load the number into ACC (immediate addressing is used)
Load the contents of the specified address into ACC (direct
or absolute addressing is used)
LDI <address> The address to be used is the contents of the specified
address. Load the contents of the contents of the given
address into ACC (indirect addressing is used)
LDX <address> The address to be used is the specified address plus the
4 Processor fundamentals
124
Opcode
Instruction
Operand
Explanation
4
JMP <address> Jump to the specified address
JPE <address> Following a compare instruction, jump to the specified
address if the comparison is True
JPN <address> Following a compare instruction, jump to the specified
address if the comparison is False
Compare instructions
Instruction Explanation
Opcode Operand
CMP <address> Compare the contents of ACC with the contents of the
specified address (direct or absolute addressing is used)
CMP #n Compare the contents of ACC with the number n
CMI <address> The address to be used is the contents of the specified
address; compare the contents of the contents of the given
address with ACC (indirect addressing is used)
The contents of the accumulator are always compared
▲ Table 4.8 Compare instructions
4
the assembly language instruction LDM #200 would store 200 in the
accumulator.
Relative addressing – the memory address used is the current memory address
added to the operand. For example, JMR #5 would transfer control to the
instruction 5 locations after the current instruction.
Symbolic addressing – only used in assembly language programming. A label
is used instead of a value. For example, if the memory location with address
labelled MyStore contained the value 20, the assembly language instruction
4 Processor fundamentals
The same task written in assembly language could look like this:
Label Opcode Operand
start: LDD first
ADD second
ADD third
STO total
END
first: #20
second: #30
third: #40
total: #0
126
When this section of code is executed, the contents of ACC, CIR and the
The same task written in assembly language would require the use of the index
register (IX). The assembly language program could look like this:
Label Opcode Operand Comment
LDM #0 Load 0 into ACC
STO total Store 0 in total
STO counter Store 0 in counter
LDR #0 Set IX to 0
loop: LDX number Load the number indexed by IX into ACC
ADD total Add total to ACC
STO total Store result in total
INC IX Add 1 to the contents of IX
LDD counter Load counter into ACC
INC ACC Add 1 to ACC
STO counter Store result in counter
CMP #3 Compare with 3
JPN loop If ACC not equal to 3 then return to start of
loop
END
number: #5 List of three numbers
#7
#3
counter: counter for loop
total: Storage space for total
127
4
each memory location contains 16 bits, the symbol table for this small section
of program would look like this:
Label Address
loop 104
number 115
counter 118
total 119
4 Processor fundamentals
When this section of code is executed the contents of ACC, CIR, IX and the
variables used can be traced using a trace table:
CIR Opcode Operand ACC IX Counter 118 Total 119
100 LDM #0 0
101 STO total 0 0
102 STO counter 0 0 0
103 LDR #0 0 0 0 0
104 LDX number 5 0 0 0
105 ADD total 5 0 0 0
106 STO total 5 0 0 5
107 INC IX 5 1 0 5
108 LDD counter 0 1 0 5
109 INC ACC 1 1 0 5
110 STO counter 1 1 1 5
111 CMP #3 1 1 1 5
112 JPN loop 1 1 1 5
104 LDX number 7 1 1 5
105 ADD total 12 1 1 5
106 STO total 12 1 1 12
107 INC IX 12 2 1 12
108 LDD counter 1 2 1 12
109 INC ACC 2 2 1 12
110 STO counter 2 2 2 12
111 CMP #3 2 2 2 12
112 JPN loop 2 2 2 12
104 LDX number 3 2 2 12
105 ADD total 15 2 2 12
106 STO total 15 2 2 15
107 INC IX 15 3 2 15
108 LDD counter 2 3 2 15
109 INC ACC 3 3 2 15
110 STO counter 3 3 3 15
111 CMP #3 3 3 3 15
112 JPN loop 3 3 3 15
113 END
128
number1: #30
number2: #40
number3: #20
number4: #50
total: #0
129
0 0
0 1
1 0
1 1
Key terms
Shift – moving the bits stored in a register a given number of places within the
register; there are different types of shift.
Logical shift – bits shifted out of the register are replaced with zeros.
Arithmetic shift – the sign of the number is preserved.
Cyclic shift – no bits are lost, bits shifted out of one end of the register are introduced
at the other end of the register.
Left shift – bits are shifted to the left.
Right shift – bits are shifted to the right.
Monitor – to automatically take readings from a device.
Control – to automatically take readings from a device, then use the data from those
readings to adjust the device.
Mask – a number that is used with the logical operators AND, OR or XOR to identify,
remove or set a single bit or group of bits in an address or register.
4
arithmetic and cyclic shifts.
Right shift – bits are shifted to the right; gives the direction of shift for
logical, arithmetic and cyclic shifts.
Table 4.10 shows the logical shifts that you are expected to use in assembly
language programming.
Instruction Explanation
Opcode Operand
Table 4.11 shows the instructions used to check, set and clear a single bit or
group of bits.
Instruction Explanation
Opcode Operand
AND n Bitwise AND operation of the contents of ACC with the
operand
AND <address> Bitwise AND operation of the contents of ACC with the
contents of <address>
XOR n Bitwise XOR operation of the contents of ACC with the
operand
XOR <address> Bitwise XOR operation of the contents of ACC with the
contents of <address>
OR n Bitwise OR operation of the contents of ACC with the operand
OR <address> Bitwise OR operation of the contents of ACC with the
contents of <address>
The results of logical bit manipulation are always stored in the ACC. <address> can be an
absolute address or a symbolic address. The operand is used as the mask to set or clear
bits
▲ Table 4.11 Instructions used to check, set and clear a single bit or group of bits
131
4 Opcode
LDD
Operand
sensors
Comment
Load content of sensors into ACC
AND #B100 Mask to select bit 3 only
CMP #B100 Check if bit 3 is set
JPN process Jump to process routine if bit not set
LDD sensors Load sensors into ACC
XOR #B100 Clear bit 3 as sensor 3 has been processed
4 Processor fundamentals
ACTIVITY 4C
1 a) State the contents of the accumulator after the following instructions
have been executed. The accumulator contains B00011001.
i) LSL #4
ii) LSR #5
b) Write an assembly language instruction to:
i) set bit 4 in the accumulator
ii) clear bit 1 in the accumulator.
2 a) Describe the difference between arithmetic shifts and logical shifts.
b) Explain, with the aid of examples, how a cyclic shift works.
c) This register is shown before and after it has been shifted. Identify the
type of shift that has taken place.
0 0 1 1 0 1 0 1
1 0 1 0 1 0 0 0
End of chapter 1 a) Write these six stages of the Von Neumann fetch-execute cycle in the correct
questions order.[6]
– instruction is copied from the MDR and is placed in the CIR
– the instruction is executed
– the instruction is decoded
– the address contained in PC is copied to the MAR
– the value in PC is incremented by 1
– instruction is copied from memory location in MAR and
placed in MDR
b) Explain how the following affect the performance of a computer system.
i) Width of the data bus and address bus. [2]
ii) The clock speed. [2]
iii)Use of dual core or quad core processors. [2]
c) A student accessed the BIOS on their computer. They increased the clock
speed from 2.5 GHz to 3.2 GHz.
Explain the potential dangers in doing this. [2]
132
4
sending data to peripherals. [5]
b) Describe how interrupts can be used to service a printer printing out a large
1000 page document. [5]
3 a) i) Name three special registers used in a typical processor. [3]
ii) Explain the purpose of the three registers named in part i). [3]
b) Explain how interrupts are used when a processor sends a document to a
printer.[4]
133
4 Opcode
Instruction
Operand
Explanation
LDD <address> Direct addressing. Load the contents of the given address
to ACC
STO <address> Store the contents of ACC at the given address
INC <register> Add 1 to the contents of the register (ACC or IX)
ADD <address> Add the contents of the given address to the contents of
4 Processor fundamentals
ACC
AND <address> Bitwise AND operation of the contents of ACC with the
contents of <address>
CMP #n Compare the contents of ACC with the number n
JMP <address> Jump to the given address
JPE <address> Following a compare instruction, jump to <address> if the
compare was True
JGT <address> Following a compare instruction, jump to <address> if
the content of ACC is greater than the number used in the
compare instruction
END End the program and return to the operating system
134
4
Start at LOOP and finish when EXIT is reached. [4]
BITREG COUNT VALUE ACC
B00001010 0 1
135