Skip to content

Introduction

Computer Organisation

Computer Organisation

A computer is a complex systems made up of many components. The study of these components is the study of Computer Organisation.

To create the complex systems that is a computer, we organise the components of a computer into layers. Each layer abstracts away the layer below it by providing an interface that can be used by the layer above it. Similarly, it communicates with the layer below it by using the interface provided by them.

Abstraction is a standard approach in any complex projects. By having an abstraction, we can change the implementation details without affecting the layers above or below it. Therefore, the works and/or optimisations can be done by several groups concurrently.

Application Software
Compiler
Operating System
Assembler
Linker Loader Scheduler Device Drivers
Instruction Set Architecture (ISA)
Processor Memory I/O System
Datapath & Control Design
Digital Logic Design
Circuit Design
Transistors

Above the instruction set architecture (ISA) is the software stack and below it is the hardware stack. We will focus on the components in bold.

Computer Science
  • CS2106: Operating System
  • CS4212: Compiler

Abstraction

As a programmer, you may have wondered how your program is run. There is one abstraction of interest in this aspect: the language abstraction. First, note that your computer can only recognise two alphabets: 0 and 11. As such, your computer cannot actually understand your program as you understand it. Instead, we will have to first translate the program into a language that your computer can understand.

This translation is often called compilation. It typically involves 3 languages: high-level language, assembly language and machine code3.

graph LR A["High-Level Programming Languages"] -- compile --> B["Assembly Language"] B -- assemble --> C["Machine Code"]

To illustrate, we will use the example of summation of the first ten square numbers starting from 1. In other words,

\(\sum^{10}_{i=1} i^2\)

Hopefully you can easily write a simple code to that by now. A possible implementation in 3 high-level languages are shown below2:

Sum of Squares
1
2
3
4
int i, a = 0;
for(i=1; i<=10; i++) {
  a = a + i*i;
}
Sum of Squares
1
2
3
4
var i, a = 0;
for(i=1; i<=10; i++) {
  a = a + i*i;
}
Sum of Squares
1
2
3
a = 0
for i in range(1,11):
  a = a + i*i

Notice how these languages are close to English. Unfortunately, it hides the actual complexities of what is happening behind the scene. After a compilation into MIPS (the assembly language for our module), the 4 line codes (or 3 lines for Python) is now a 6 lines instructions:

Sum of Squares
1
2
3
4
5
6
      addi $t1, $zero, 10
      add  $t1, $t1  , $t1
      addi $t2, $zero, 10
Loop: addi $t2, $t2  , 10
      addi $t1, $t1  , -1
      beq  $t1, $zero, Loop

You do not have to understand the meaning for now, but note that the for-loop disappear. It is replaced with a jump to a line above. This, in essence, is how a loop is constructed. As a flowchart, it looks like the following.

graph TD S([start]) --> A["(1) addi $t1, $zero, 10"] A --> B["(2) add $t1, $t1 , $t1"] B --> C["(3) addi $t2, $zero, 10"] C --> D["(4) addi $t2, $t2 , 10"] D --> E["(5) addi $t1, $t1 , -1"] E --> F[/"(6) beq $t1, $zero, (4)"/] F -- true --> D F -- false --> G([end])

To really allow the program to be executed by a computer, we will actually need to assemble the assembly language into a machine code. This process is often a simple one-to-one translation into binary.

Sum of Squares
1
2
3
4
5
6
00100000000010010000000000001010
00000001001010010100100000100000
00100000000010100000000000001010
00100001010010100000000000001010
00100001001010011111111111111111
00010001001000001111111111111101
Sum of Squares
1
2
3
4
5
6
0x2009000A
0x01294820
0x200A000A
0x214A000A
0x2129FFFF
0x1120FFFD

Thus, 6 lines in MIPS is translated into 6 lines in machine code. We also often write this in hexadecimal, which is much shorter (especially if you ignore the 0x).

Computer

What is a Computer?

Given that a computer is such a complex system, what do we actually mean when we say that a device is a computer? A possible definition is as follows:

Computer

A computer is a device capable of solving problems according to the given set of instructions (i.e., programs). It is simply a device that augments our power of storage and speed of calculation.

A counterpart in locomotion is an automobile. We can define an automobile as a device that augments our power of locomotion. In this case, you -a programmer- can be compared to a driver.

In the context of computer organisation, we are interested in the components and how they work together. However, even that is still quite complex. So, we focus mainly on the Central Processing Unit (CPU) with some excursions into Random Access Memory (RAM). More often than not, we will try to abstract out other components such as the hard drive.

Without such abstraction, studying a CPU can be daunting. You can judge for yourselves by looking at layout of a motherboard below4.

PC Motherboard

Of course, we will also not go into the nitty-gritty details of modern processor. You can see for yourselves how complex a modern processor is. After all, modern processor contains more than 2 trillion transistors.

Pentium Processor

Fortunately, with a correct abstraction, you can actually see how these transistors are arranged. If the diagram above is still too complex, we can further simplify it into three components:

ALU

  1. Arithmetic Logic Unit (ALU)
  2. Control Unit
  3. Memory Unit

Why Study Computer Organisation?

Edsger Dijkstra

"Computer science is no more about computers than astronomy is about telescopes."

Nevertheless, it is still going to be partially about computers. In fact, computer organisation is really the study of internal working, structuring and implementation of a computer system. However, this study has to be done through a particular level of abstraction. The level of abstraction chosen for this module is the middle portion: above the digital logic level, but below the operating system level.

If you are still on the fence about this, we would like to offer a few other reasons:

  • You want to call yourself a computer scientist/specialist.
  • You want to build software people use.
  • You need to make purchasing decisions.
  • You need to offer "expert" advice.
  • You want to understand "performance" (COD chapter 4) and how hardware/software affect performance.
    • Algorithm determines number of source-level statements (CS1010, CS2030, CS2040, CS3230).
    • Language, compiler and architecture determine machine instructions (COD chapters 2 & 3).
    • Processor and memory determine how fast instructions are executed (COD chapters 5, 6 and 7).

  1. 0 and 1 need not be represented as numbers and can be represented as many things. For instance, it can be represented as voltages, water, etc

  2. As you will see later, the code for C actually requires preamble. This is merely the core of the code. 

  3. There are actually an even lower abstraction than machine language, but we will not go into that until the second half of the semester. 

  4. Credit Computer Hardware Explained