4.1 CPU Architecture

Specification

  • Show understanding of the basic Von Neumann model for a computer system and the stored program concept

  • Show understanding of the purpose and role of registers, including the difference between general purpose and special purpose registers

    • Special purpose registers including:

      • Program Counter (PC)

      • Memory Data Register (MDR)

      • Memory Address Register (MAR)

      • The Accumulator (ACC)

      • Index Register (IX)

      • Current Instruction Register (CIR)

      • Status Register

  • Show understanding of the purpose and roles of the Arithmetic and Logic Unit (ALU), Control Unit (CU) and system clock, Immediate Access Store (IAS)

  • Show understanding of how data are transferred between various components of the computer system using the address bus, data bus and control bus

  • Show understanding of how factors contribute to the performance of the computer system, including

    • processor type and number of cores

    • the bus width

    • clock speed

    • cache memory

  • Understand how different ports provide connection to peripheral devices, including connection to

    • Universal Serial Bus (USB)

    • High Definition Multimedia Interface (HDMI)

    • Video Graphics Array (VGA)

  • Describe the stages of the Fetch-Execute (F-E) cycle

    • Describe and use 'register transfer' notation to describe the F-E cycle

  • Show understanding of the purpose of interrupts, including:

    • possible causes of interrupts

    • applications of interrupts

    • use of an Interrupt service (ISR) handling routine

    • when interrupts are detected during the fetch-execute cycle

    • how interrupts are handled

The CPU and the Fetch Decode Execute Cycle

The PowerPoint (on main page) should give the theory content you need, but this useful site (a little dated now) explains some of these concepts in much more detail (a lot more than is needed for the exam, but does help cement understanding). It also goes into detail on things such as the memory controller and how addressing links all the different 'things' such as RAM, video memory, I/O controllers, etc., together.

The CPU and the Fetch Decode Execute Cycle

The Central Processing Unit (CPU) is the brain of the computer. It is the component that does all of the clever calculations. It reads the instructions in a program, decides what to do about each instruction and then sends out signals to all of the different pieces of hardware to make things happen. This is quite a complicated idea so we need to produce a model (an abstraction) that we can start working with.

Programs are simply sets of instructions that a programmer has written. When you want to 'run' a program, you might double-click on it in a computer system to 'open' it. When we double-click on it, we are sending an instruction to the operating system to go and find the program on the hard drive, copy it and put the copy in RAM. You can see a copy of part of a program on the left. We won't worry about what the instructions all mean. We will just accept that this is what a typical set of program instructions looks like.

a) To 'run' a program, the CPU has to get the first instruction in the program.

b) It puts the address of the instruction it wants to fetch on the address bus.

c) The computer then fetches the instruction given by this address.

d) It fetches the instruction by putting it on the data bus.

e) The instruction is passed back to the CPU.

f) The CPU then 'decodes' the instruction.

g) What this simply means, is it decides what to do with the instruction.

h) Then, once it has decided what to do, it does it!

i) Carrying out an instruction is called 'executing' the instruction.

j) The CPU sends out signals to all of the other hardware components so that the instruction is executed.

That's it! The CPU has fetched an instruction, decoded it and then executed it. When it has finished one instruction, it does the next one, and the next one and the next one. In fact, this is all the CPU does, all day long.

The register known as the Program Counter

We know that computers have different types of memory. One type of memory is RAM. Another type of memory is the Register. Registers are very fast and they help the CPU carry out this process of FETCH - DECODE - EXCEUTE. One register, for example, is called the Program Counter. You can think of it as a box that holds a number. Its job is to keep track of the next address that the CPU must fetch, once the CPU has finished its current instruction (the CPU can only work on one FETCH - DECODE - EXECUTE cycle at a time).

For example, if the first instruction to be carried out in a program in RAM was in memory location 2435 (see the diagram above), the operating system puts 2435 into the Program Counter. Now, when the CPU is ready to run the program, it looks in the Program Counter, sees 2435 and fetches whatever is at that location. Automatically, once 2435 has been fetched, the Program Counter increases by one, to 2436. When the CPU has finished fetching, decoding and executing the instruction, it simply goes back to the Program Counter, looks at the address in there and repeats the above process, increasing the Program Counter by one every time an instruction has been fetched. This is a very simple but effective way for the CPU to know what to do next. The thing is, the CPU can do all of this really quickly - billions and billions of times a second!!

Extra note:

It is said that the PC increments by 1 address. However, in reality, if a given instruction is 32 bits in length, the PC will point 4 bytes higher, where the next instruction can be found.

Registers

A Von Neumann CPU (the type of CPU you get in nearly all personal computers) has a number of 'registers'. These are very fast memory circuits. You can think of each register as a box which holds a piece of data useful to the CPU. These pieces of data allow the CPU to quickly 'fetch' and then 'decode' and then 'execute' the instuctions held in RAM that are part of a program, one instruction at a time.

The registers you should know about include:

  • Program Counter (PC) - this holdes the address of the next instruction to be fetched and execurted.

  • Current Instruction Register (CIR) - this holds the current instruction being executed.

  • Memory Address Register (MAR) - this holds the RAM address you want to read to or write from.

  • Memory Data Register (MDR) - this holds the data you have read from RAM or want to write to RAM.

  • Accumulators - these hold the data being worked on and the results of arithmetic and logical operations.

  • Status Register - this holds information about the last operation e.g. whether the least sum done produced a negative result.

  • Interrupt Register - this holds details about whether an interrupt has happened.

  • Index register - this is a very fast counter, that is used e.g. when you have to work though a block of data and need to keep track of which piece of data you are at.

Using registers to execute an instruction in a program.

Consider the following situation:



Note in this example, it has not used binary either for the RAM address or the contents, in order to make things easier to understand!

How are the registers used to read an instruction in a program?


FETCH

  • The CPU reads the contents of the Program Counter (the address of the next instruction to be fetched), decoded and executed. In our case memory address 3254.

  • The contents (address 3254) are then put on the MAR.

    • The address in the MAR is then located in RAM.

  • The contents of this address are stored in the MDR.

  • The MDR now holds the instruction that must be executed.

  • The instruction in the MDR is then copied to the CIR, as we will often need to use the MDR again to complete the execution of an instruction (e.g. indirect addressing).

  • As soon as it is copied, the PC increments. PC = PC + 1, or 3255

DECODE

  • The contents of the CIR are divided. Part of the instruction might be an operation (like ADD) and part of the instruction might be data, or in our case, an address where data can be found, like 75567. The ADD part is known as the OP-CODE (Operator) and the data part is known as the OPERAND.

  • The operator (ADD) is decoded by the Control Unit in the CPU, so it knows what it has to do (ADD in our case).

  • The operand 75567 is put back on the MAR.

  • The contents of 75567 is then found in RAM and put on the MDR.

EXECUTE

  • The instruction can now be executed. Arithmetic and logical instructions are carried out using the Accumulator(s) in a CPU.

  • Signals are sent out to different parts of the CPU to execute the instruction ADD.

  • In our example, this will result in adding 4500 to whatever is in the Accumulator, and then over-writing the contents of the Accumulator with the result of the addition.

The way registers are used to run programs is often known as the FETCH - DECODE - EXECUTE cycle. This is because that is all the CPU actually does. It fetches instructions, decodes them and then executes them. It does this very quickly indeed, but that is all it does. It is why you sometimes read that computers aren't very clever!

Register Transfer Notation

This symbolic notation allows us to show the transfer and operations carried out by registers. It works a little like variable assignment notation in pseudocode.

[] denote contents of location. I.e. The contents of a given register

MAR <-- [PC] - Transfer contents of PC to MAR

PC <-- [PC] + 1 - Increment the PC

MDR <-- [[MAR]] - [[MAR]] indicates that the contents of the MAR itself an address

CIR <-- [MDR] - Copy contents of MDR to CIR

Interrupts

Applications of interrupts

Interrupts are also covered in 5.1 The Operating System, from the perspective of the operating system.

Interrupts are signals generated by a hardware device or by a software application that tell the CPU it needs some CPU time. A CPU can only ever do one job at a time. If it is working on one job and another job needs some CPU processing time then that other job sends a signal, an interrupt, to the processor. When the processor receives the signal, it does one of a number of things.

  • The CPU might stop what it is doing and start servicing the device or software that sent the signal.

  • The CPU might carry on doing its current job until it is finished and then service the device or software that sent the signal.

  • The CPU might carry on doing its current job and then service other interrupts that have happened. When it has done those, it then services the interrupt in our discussion!

To summarise, an interrupt is a signal sent to the CPU by a device or by a program that indicates to the CPU that a device or program needs some 'CPU time'. The CPU must stop what it is doing and run a program, a piece of software, for that particular type of interrupt, known as an interrupt handling routine. The first decision the CPU must make is when to run the interrupt handling routine - how urgent is it compared to what it is currently doing and compared to what else is waiting to be done!

Different kinds of interrupts

1) A timer interrupt

This is an interrupt that occurs at fixed time intervals. There are circuits in a computer that can generate an interrupt signal every 1 ms, for example. This could then be used to signal to the CPU to refresh the VDU, for example.

2) A program error interrupt

When a program is written, it may need to do maths sums! If you divide any number by zero, the result is meaningless and the program you are running will get confused! The CPU needs to know about this so a 'program error' interrupt signal is sent to the CPU to tell it what has happened. The CPU can then take action, for example, by ending the program and reporting the error.

3) A hardware error interrupt

Your computer is made up of a lot of different hardware devices. Generally, they work well and do what they are supposed to do. But like any electrical or mechanical device they will one day fail. When that happens, the CPU needs to know about it. A device that has failed sends an interrupt signal to the CPU. The CPU can then, for example, put a message on the screen to notify the user of the problem.

4) I/O interrupts

When a file is sent to a printer, it will go to a buffer. The buffer will then communicate with the printer. The reason for this is that it frees up the CPU to do other jobs. Remember, the CPU can only do one job at a time. If it is managing the printing of a file, it can't be doing other things. This, however, isn't a very efficient use of CPU time because printing is slow compared to the speed CPUs work at. Sometimes, however, the file that you want to print can't fit into the whole of the buffer at once. Only part of it is put in. The CPU then gets on with something else while the printer buffer empties. When it gets close to being empty, the printer sends an I/O interrupt to the CPU, so it can be given more of the file.

Another example of an I/O interrupt is the one generated every time you press a key on the keyboard. When you press a key, an interrupt is sent to the CPU. The CPU stops what it is doing and then manages the reading in of the key code into a buffer. Then it goes back to doing what it was doing before. At some point, the CPU will return to the keyboard buffer and retrieve the contents for use somewhere.

How does the Interrupt process work?

The CPU has a special register called the 'interrupt register'. You can imagine this, for example, as a two-byte number (in other words, 16 bits). When a particular interrupt happens, the signal sent causes the correct bit in the interrupt register to be made a 'one'. Here is an example.

  • This is the interrupt register: 0000 0000 0000 0000

  • The DVD drive fails, so a 'hardware failure' interrupt signal is sent to the interrupt register.

  • The bit that is used to signal hardware failure is bit 3 so that bit is set to one. (The bit on the right-most side, the least significant bit, is bit zero.)

  • The interrupt register now looks like this: 0000 0000 0000 1000

So what happens next?

  • At the beginning of each FDE cycle (or end), each bit in the interrupt register is checked in turn.

  • If a bit has been set, that would indicate an interrupt has happened.

  • The CPU decides whether to service the interrupt immediately, or leave it till later. For example, if 2 interrupts have happened at the same time, one of them has to wait! Which one? That depends upon which one is the least important! Some interrupts are more important than others and so need to be done before others. What about the situation where one interrupt is currently being serviced by the CPU and another happens? Again, it depends on how important the new interrupt is compared to the one already being done. If it is more important, then the CPU will want to service it immediately.

  • When the CPU decides to service an interrupt, it stops processing the current job, 'pushing' the contents of its registers onto the stack. This would include, for example, the contents of the Program Counter and the Accumulator. The CPU is now free to work on another piece of software but can return to what it was doing after the interrupt has been serviced because it has saved where it was.

  • It then transfers control to the interrupt handling software for that type of interrupt. You can read more about how it does that (using the Vectored Interrupt Mechanism) later in this chapter.

  • When it has finished servicing the interrupt, the contents of the stack are 'popped' back into the appropriate registers and the CPU continues from where it left off before the interrupt happened.

More on the prioritisation of interrupts

A computer needs to make a decision! It has to decide what priority to give each of the different kinds of interrupts, in case it has to service more than one kind of interrupt simultaneously. One possible order is shown below. I have decided that the most important kind of interrupt is the hardware failure interrupt. If anything fails, I want the computer to stop what it is doing immediately and service it - attempt to sort out the problem and also tell me about it. I have equally decided that I/O requests are the least important interrupts and can be serviced last if a choice between which interrupt to service has to be made.

  1. Hardware failure: Priority 1 (most important)

  2. Program error: Priority 2

  3. Timer: Priority 3

  4. I/O: Priority 4

The Vectored Interrupt Mechanism

When an interrupt happens, the CPU needs to jump to the relevant software routine. How does it know where it is? It can do this by using a technique known as 'indirect addressing'. This is fully explained in the chapter on low-level languages but briefly, when an interrupt happens, the CPU identifies what kind of interrupt it is. With every type of interrupt, there is an associated memory address, known as a vector. This memory address, or vector, holds the address of the relevant interrupt handling routine. So when an interrupt happens, the CPU jumps to the vector, gets the address of the start of the interrupt handling routine, loads it into the Program Counter and processing continues. For example:

Points 1 and 3 give MORE detail than you need to know, but are included for completeness

  • The CPU is working on a word processing application. The interrupt register (IR) is 0000 0000 0000 0000.

  • A software error occurs that causes a program error interrupt to occur.

  • Bit 6, used for program error interrupts, is set. The interrupt register is now 0000 0000 0100 0000

  • At the start (or end) of the FDE cycle, the interrupt register is checked and the CPU sees that an error has occurred.

  • The processor will identify the source of the interrupt

  • The processor will then check the priority of the interrupt

  • It isn't currently servicing any other interrupt and no other higher priority interrupt has occurred so it decides to service this routine.

  • Lower priority interrupts are disabled

  • It pushes the contents of the CPU’s registers onto the stack, which is just a special storage area. you have to take a snapshot of where the CPU is currently up to because after servicing the interrupt, it is going to have to be returned to the state it was in before the interrupt happened.

  • It will look up the correct address for the given type of interrupt in a table

  • It jumps to the address (known as a vector) for that type of interrupt.

  • At that vector address, it finds another address! This is the interrupt service routine (ISR)

  • It loads that address into the Program Counter.

  • The interrupt routine completes.

  • lower priority interrupts are re-enabled

  • The contents of the stack are popped into the CPU's registers.

  • The CPU continues doing whatever it was doing before the interrupt happened.

USB

This section was taken from an excellent reference article on USB. The full article can be found here.

USB is a universal serial bus standard and a technical specification for input and output interfaces. It is widely used in information transformation products such as personal computers and mobile devices. The USB interface has hot-swappable, plug-and-play functions, and can be connected to a variety of external devices, such as a mouse and keyboard, etc. Our mobile phone charging uses the USB connector. These USB devices give us great convenience. USB chargers, USB connectors, and USB cables are all USB the same? What is USB 2.0 and USB 3.0? What is a low speed, full speed, and high speed? What are Type-A, Type-B, and Type-C? Here you will get a full answer.

USB Protocols

The USB 1.0/2.0/3.0 we often say refers to the technical specifications. The biggest difference among them is speed, that is, they indicate the speed of USB transfer files. The maximum transmission bandwidth of USB 3.0 is up to 5.0Gbps (640MB/s). Now many high-speed U disks or mobile hard drives use USB 3.0 or USB 3.1. USB also includes the old USB 1.1 standard and USB 2.0 standard. The traditional maximum transfer rate of USB 1.1 is 12Mbps. Generally, manufacturers call its products that comply with the USB 1.1 standard "full-speed USB." When the high-speed USB 2.0 was first introduced, the highest transmission rate was only 240Mbps. Later, the USB Promoter Group increased the rate to 480Mbps in October 1999, which is 40 times faster than the traditional USB 1.1. USB 2.0 is backwards compatible with USB 1.1. Of course, USB 1.1 devices are also "upward compatible" with USB 2.0, however, they cannot realize the transmission capability of USB 2.0 and automatically transmit at low speed. The maximum length of the USB 2.0 cable is 5 meters, but if five USB adapters are used, the maximum length can be up to 30 meters.

Although you'll still be able to connect old-school devices with USB Type-A or USB Type-B connectors, now you have more choices, that is USB4. USB4 is a USB system specified in the USB4 specification which was released in version 1.0 on 29 August 2019 by USB Implementers Forum. It leverages the Thunderbolt 3 protocol to deliver speeds up to twice as fast as the USB version it replaces. The USB4 architecture defines a method to dynamically share a single high-speed link with multiple end device types to best serve the transfer of data by type and application.

Type-A/B/C determines the appearance of the USB ports. For example, the mouse, keyboard, USB flash drive and other interfaces we use are generally Type-A, which is also the most widely used interface. Type-B is more common in printers, monitors and other devices. In the past, Micro USB and Mini USB commonly used in mobile phones were portable versions of USB 2.0. The appearance of Type-C is very recognizable, slimmer. Its biggest feature is flippability, that is, the USB-C connector has no up or down orientation, so you never have to flip it over to plug it in.

1) Type-A: Standard USB Port

Type-A is the most common type of USB port on computers. It has a notable feature: direction requirements. The connector (male port) must be inserted into the interface (female port) from a certain direction, in addition, because the appearance of the two sides of the USB male port is very close, this insertion process often makes mistakes.

2) Type-B: Commonly used in printer equipment

Type-B is the most common and popular data interface type on printers and displays, and some displays will also use it.

3) Type Micro-B: USB standard for mobile devices

Currently, most Android phones use the Micro USB interface (USB Micro-B), which is still widely used in various mobile portable devices.

4) Type-C: It will become mainstream

Although Type-C has just appeared, it is foreseeable that as the USB Type-C technology matures, various notebooks, tablets and even smartphones in the future will begin to use the USB Type-C interface.

Type-C is the same as the USB C because the USB C is also called USB Type-C. However, there are slight differences between them. Let’s look at the following facts.

Features of USB-C Connector:

1) Ultra-thin

The old USB port size is 14mm * 6.5mm, while the USB-C is only 8.4mm * 2.6mm.

2) No Orientation

Like the Lightning, there will be no problem regardless of whether it is plugged in or reversed. It claims to be able to up to 10,000 times of repeated plugging and unplugging.

3) Fast Transfer Rate

The maximum transfer rate of the USB-C port is 10Gb per second, which is much faster than USB 3.0.

4) Two-way Transmission

Unlike the old USB port, the power can only be transmitted in one direction. The USB-C port is bidirectional, which means that it can have two transmission power modes. Therefore, users can not only use laptops to charge mobile devices but also use other devices or mobile power sources to charge laptops.

5) Strong Power Supply Capability

The standard specification cable equipped with a Type-C connector can pass 3A current, and it also has a super USB power supply capacity, which can up to 100W of power.

6) Backward Compatibility

USB-C can be compatible with the old USB standard, but users need to purchase an additional adapter to complete the compatibility.

USB-C refers to the Type C port that uses the USB 3.1 standard, but it should be noted that USB-C is not equal to Type C. Because there are many Type C devices that can only reach USB 2.0 or USB 3.0 transfer rate.

With the improvement of technology, Type-C also supports the USB3.1 standard. Because the voltage and current increase, the coding consumption is reduced, from 20% of USB 3.0 to 3%. In other words, users can quickly transfer data and video through Type-C, or charge faster. The standard also allows users to charge other devices with their mobile phones. As for the display, when using Type-C for data transmission, there is no need to use another power cord to power the display, which solves the problem of messy desktop cables. Even the relatively high-end HDMI and DP ports cannot do it.

The USB-C connector can be expanded into three: power supply/ USB transmission/ VGA or HDMI, which is the next-generation mainstream USB interface. The type-c cable is also of great help to the arrival of the 5G. Because the port of it becomes smaller, the flattening of electronic products is promoted. And in the transmission of audio and video, the TC data line has a faster speed. At present, well-known technology manufacturers such as Sony and Apple have widely used type-c cables on their electrical devices because they can support multiple formats and reduce the limitations of USB. In short, the arrival of the 5G actually wants everyone to experience faster bandwidth, so the corresponding supporting facilities should also keep up. The type-c cable is undoubtedly one of them.