Ch.4 Processor Fundamentals
Ch.4 Processor Fundamentals
Clock
A vital part of the control unit is a clock that is used by the unit to synchronise processes.
The CPU will have a defined frequency for its clock cycle, which is usually referred to as the
clock speed. The frequency defines the minimum period of time that separates successive
There are two clocks.
Internal clock
It controls the cycles of activity within the processor.
System clock
It controls the cycles activities outside the processor. The clock cycle is the one controlled by the system clock
which will have settings that allow one data transfer from memory to take place in the time defined for one cycle.
Types of registers
A register is either general purpose or special purpose.
The Accumulator is used to store a single value at any one time. A value is stored in the Accumulator that is to be used by the
ALU for the execution of an instruction.
The ALU can then store a different value in the Accumulator after the execution of the instruction.
Note:
The first is that the MDR must act as a buffer. This is because transfers of data inside the processor take place
much more quickly than transfers outside the processor.
For all of the special-purpose registers, except for the status register, the contents represent one value. For the
status register each individual bit is used as a logical flag. The bit is set to 1 if a condition is detected.
Examples are the carry flag, the negative flag and the overflow flag.
There will be buses inside the CPU. These are not considered here. The system bus connects the CPU to the
memory and to the I/O system.
The system bus allows data flow between the CPU, the memory and input or output (I/O) devices.
a location in memory which is to be read from or written to or it can be to the I/O system to identify the
The sole function of the address bus is to carry an address. This address is loaded on to the bus from the MAR as
and when directed by the control unit. The address specifies a location in memory or an I/O component which is
due to receive data or from which data is to be read.
The address bus is a unidirectional. It can only be used to send an address to a memory controller or an I/O
controller. It cannot be used to carry an address back to the CPU.
• clock speed
• cache memory
Clock speed
The processor clock speed could be a very important factor governing the processing speed of the system. This is
because one clock cycle defines the shortest possible time that any action can take. Actually, none of the
components outside of the processor can work anywhere near as fast as the processor can. The components that
are directly addressable by the processor, which can be referred to as the immediate access store (IAS), can only
accept data from or provide data to the processor at speeds much slower than the processor speed.
Cache memory
Cache memory is the fastest component of the IAS. Performance improves with increased storage size for the
cache and with increased rate of access. Fastest access is obtained by having all or part of the cache on the CPU
chip.
Word
A small number of bytes that can be handled as a unit by the computer system
Typical word lengths are 16, 32 or 64 bits; that is, 2, 4 or 8 bytes, respectively. The word length will influence the
system architecture design in regard to the capacity of the components. For example, it is usual for the size of
registers to match the word length. Word length also has to be considered when making decisions about bus
widths.
I/O ports
Each I/O device is connected to an interface called a port. Each port is connected to the I/O or device controller. This controller
handles the interaction between the CPU and an I/O device. A port is described as ‘internal’ if the connected I/O device is an
integral part of the computer system. An external port allows the computer user to connect a peripheral I/O device.
The computer is at the root of this hierarchy and can handle 127 attached devices.
Devices can be attached while the computer is switched on and are automatically configured.
The HDMI technology is used with devices such as an HDTV, Projector, DVD player, or Blu-ray player.
If we assume that a program is already running, then the program counter will already hold the address of the next
instruction. In the fetch stage, the following steps will now happen.
1 This address in the program counter is transferred within the CPU to the MAR.
• the instruction held in the address pointed to by the MAR is fetched into the MDR
3 The instruction stored in the MDR is transferred within the CPU to the CIR.
• However, the instruction just loaded might be a jump instruction. In this case, the program counter contents will
have to be updated in accordance with the jump condition. This can only happen after the instruction has been
decoded.
In the decode stage, the instruction stored in the CIR is received as input by the circuitry within the control unit.
Depending on the type of instruction, the control unit will send signals to the appropriate components so that the
execute stage can begin. At this stage, the ALU will be activated if the instruction requires arithmetic or logic
processing.
MAR ← [PC]
PC ← [PC] + 1
MDR ← [[MAR]]
CIR ← [MDR]
Decode
Execute
Note:
Square brackets around a register abbreviation show that the content of the register is being moved. This
movement might also include an arithmetical operation. When two data operations are placed on the same line
separated by a semi-colon, this means that the two transfers take place simultaneously. The double pair of
brackets around MAR on the second line needs careful interpretation. The content of the MAR is an address; it is
the content of that address which is being transferred to the MDR.
Interrupt handling
There are many different reasons for an interrupt to be generated. Some examples are:
• a hardware faults
• user interaction
• a timer signals.
Different interrupts might have different priorities. Therefore, the processor must have a means of identifying the
type of interrupt. One way is to have an interrupt register.
Interrupt register
Interrupt register has bits to represent different type of interrupts, with each individual bit operating as
a flag for a specific type of interrupt. The existence of an interrupt is only detected at the end of a fetch–
execute cycle. This allows the current program to be interrupted and left in a defined state which can be
returned to later.
An interrupt is handled by the following steps.
• The contents of the program counter and any other registers are stored somewhere safe in memory (for example
Stack)
• The appropriate interrupt handler or Interrupt Service Routine (ISR) program is initiated by loading its start
address into the program counter.
• When the ISR program has been executed there is an immediate check to see if further interrupts need handling.
• Further interrupts are dealt with by repeated execution of the ISR program.
• If there are no further interrupts, the safely stored contents of the registers are restored to the CPU and the
originally running program is resumed.
• An instruction may not have an operand but up to three operands are possible.
• Different processors will have comparable instructions for the same operations, but the
For a particular processor, the following must be defined for each individual machine code
instruction:
• whether the opcode occupies the most significant or the least significant bits.
We will consider a simple system where there is either one or zero operands. This simple
system will be assumed to have a 16-bit address bus width. The system will have the accumulator as the only
general-purpose register.
Machine code instruction: a binary code with a defined number of bits that comprises an opcode and, most
often, one operand
The number of bits needed for the opcode depends on the number of different opcodes in the instruction set for
the processor. The opcode can be structured with the first few bits defining the operation and the remaining bits
associated with addressing. A sensible instruction format for our simple processor is shown in Figure.
This has an eight-bit opcode consisting of four bits for the operation, two bits for the address mode and the
remaining two bits for addressing registers. This allows 16 different operations each with one of four addressing
modes. This opcode will occupy the most significant bits in the instruction. Because in some circumstances the
operand will be a memory address it is sensible to allocate 16 bits for it. This is in keeping with the 16-bit address
bus.
Assembly language
Writing a substantial program as a sequence of machine code instructions would take a very long time and there
would be inevitably lots of errors along the way.
A programmer might wish to write a program where the actions taken by the processor are directly controlled. It is
argued that this is the most efficient type of program. The solution for this type of programming is to use assembly
language. As well as having a uniquely defined machine code language, each processor has its own assembly
language.
Assembly language: a low-level language related to machine code where opcodes are written as mnemonics and
there is a character representation for an operand Assembler: a program used to translate an assembly language
program into machine code
The essence of assembly language is that for each machine code instruction there is an equivalent assembly
language instruction which comprises:
Assembler (Translator)
If a program has been written in assembly language it has to be translated into machine code before it can be
executed by the processor. The translation program is called an assembler.
Using an assembly language, the programmer has the advantage of the coding being easier to write than it would
have been in machine code. In addition, the use of the assembler allows a programmer to include some special
features in an assembly language program.
DIRECTIVE
Directive: an instruction to the assembler program
A directive is an instruction to the assembler as to how it should construct the final executable machine code. This
might be to direct how memory should be used or to define files or procedures that will be used.
MACRO
Macro: A macro is a sequence of instructions that is to be used more than once in a program.
A macro to add the contents of two locations and store the result in a third
location is defined as follows.
.MACRO ADDUP NUM1, NUM2, RES
LDA NUM1
ADD NUM2
STO RES
.ENDMACRO
In the program, if say the programmer wishes to add the contents of P and Q and store the result in R.
He/She will write
ADDUP P, Q, R
At assembly, this instruction is replaced by the three instructions.
LDA P
ADD Q
STO R
Symbolic, relative and absolute addressing
When considering how an assembler would convert an assembly language program into machine code it is
necessary to understand the difference between symbolic, relative and absolute addressing.
To explain these, we can consider a simple assembly language program which totals single numbers input at the
keyboard.
Table shows the program as it would be written using symbolic addressing together with an explanation of each
instruction.
• replacement of a macro name used in an instruction by the list of instructions that constitute the
macro definition
All symbolic addresses will be put in a symbol table, giving the name of the symbol and its memory
address (either absolute or relative to the start of the program)
Each mnemonics code is replaced with its machine code equivalent, by referring to a table of op codes in
memory.
Each symbolic address is replaced with its equivalent machine code address by referring to symbol table
created in the first pass Decimal or characters items are converted into machine code and inserted into
the instructions using them Any error reported at this stage are reported
Bit manipulation
Shift operations
There are two shift instructions available:
• LSL #n
where the bits in the accumulator are shifted logically n places to the left
• LSR #n
In a logical shift no consideration is given as to what the binary code in the accumulator represents.
Because a shift operation moves a bit from the accumulator into the carry bit in the status register.
If the accumulator content represents an unsigned integer, the left shift operation is a fast way
to multiply by two. However, this only gives a correct result if the most significant bit is a zero.
For an unsigned integer the right shift represents integer division by two. For example, consider:
Logical shift : where bits in the accumulator are shifted to the right or to the left and a zero moves into
Cyclic shift : similar to a logical shift but bits shifted from one end reappear at the other end. All bit
values in the original code are retained.
Arithmetic shift: uses the shift to carry out multiplication or division of a signed integer stored in the
accumulator. The sign bit is always retained following the shift.
Monitoring systems
A monitoring system can be used to create a record of the condition of a system over a period of time. A
monitoring system is used more often to detect when a particular physical property of a system goes
outside a desired range; for example, if the CPU is too hot.
These systems require a measuring device that records a value which can be transmitted to the
computer. Such a measuring device is a called a sensor. An example of a sensor for measuring
temperature is a thermocouple, which outputs an electrical voltage that changes with temperature.
It is important to understand that in a monitoring system, a sensor does not have any built-in
intelligence, so it cannot take any action if there is a problem. If the temperature measured becomes
dangerously high it is the computer that sounds an alarm.
There are a wide variety of sensors available. For some the name indicates the property being measured
such as pressure, humidity, carbon monoxide, pH or sound. For others such as an infrared sensor there
are different methods of use. A passive infrared sensor just measures the level of infrared light received.
In other cases, there is transmission of infrared light with the sensor possibly measuring the level of the
light that is reflected back. Other sensors are given a generic name such as a motion sensor, for which
different examples will be measuring different physical properties.
Control systems
A control system has the monitoring activity plus the capability to control a system. The control element
of a monitoring and control system needs a device called an actuator. An actuator is an electric motor
that is connected to a controlling device. It might be used for switching on or off or for adjusting a
setting Note that Figure 1 includes an analogue-to-digital converter (ADC) and a digital-to-analogue
converter (DAC) as separate components. In a real system they are likely to be integral to the sensor or
actuator device. For the system shown in Figure 1 there is a continuing process where the computer at
regularly timed intervals signals the sensor to provide a measurement. If the measurement value
received by the computer is not in the desired range the computer initiates a control action. The next
timed measurement will happen after this control action has taken place. In effect this next
measurement provides feedback to the computer on the effect of the control action. Feedback is
essential in a control system.
Figure 1.
A closed-loop feedback control system is a special type of monitoring and control system where the
feedback directly controls the operation. Figure 2 shows a schematic diagram of such a system. A
microprocessor functions as the controller. This compares the value for the actual output, as read by the
sensor, with the desired output. It then transmits a value to the actuator which depends on the
difference calculated.
Figure 2.
Bit manipulation
Bit manipulation is the process of applying logical operations on a sequence of bits to achieve a required
result. Computer programming tasks that require bit manipulation include low-level device control,
error detection and correction algorithms, data compression, encryption algorithms, and optimization.
Bit mask
A bit mask is a predefined set of bits that is used to select which specific bits will be modified by
subsequent operations.
Consider a real-life case where you want to paint a window frame. If you’re not careful, you risk painting
not only the window frame, but also the glass itself. You might buy some masking tape and apply it to
the glass and any other parts you don’t want painted. Then when you paint, the masking tape blocks the
paint from reaching anything you don’t want painted. In the end, only the non-masked parts (the parts
you want painted) get painted.
A bit mask essentially performs the same function for bits -- the bit mask blocks the bitwise operators
from touching bits we don’t want modified, and allows access to the ones we do want modified.
Question