Computer Structure Fundaments

The structure of computer is simple. For hardware, computer includes Memory, Controller, Processor and I/O devices. For software, the basic element is operating system.

CPU

Central Processing Unit (CPU) is the brain of the computer. It receives data, execute commands and process the data.

CPU can also be divided into following parts according to their functions.

Name Functions
Register Store the command code, data, and address data
Controller Fetch the command, data from memory to register, and execute the I/O devices
Arithmetic Logic Unit (ALU) Operate the data in register
Clock Count signal

All parts above are connected together via electricity’s signal.

The working pipeline of CPU is as follows.

  1. Fetch command. The Controller fetches the command from memory to registers, Program Counter stores the next address of command that needs to be executed.
  2. Decoding command. The Controller decodes the command according to existed rules, recognizes operation category and the methods.
  3. Executed command. The Controller handles the action of the command. e.g. Add numbers stored in two registers, compare two numbers.
  4. Fetch data. If the command needs to handle data, the Controller will fetch the data from the memory according to the address decoded from the command.
  5. Write Back. Write the answer of command to somewhere such as the registers in CPU.

Register

There are several kinds of register in CPU.

  • There is only one Program Counter, Flag Register, Accumulation Register, Instruction Register, and Stack Register in CPU.
  • There are several Base Register, Index Registers, and General Register in CPU.

Program Counter

It store the address of the unit in memory which stores the command that needs to be executed. It control the process of the program to be executed.

When the program is executed, the process is as follows.

  1. The controller fetches the command from memory according to the the address that is stored in Program Counter
  2. The controller analyzes and processes that command
  3. The address in Program Counter will increase by 1 or change to the address according to the conditional/loop command(JMP command in Assembly language), which points to the unit which stores the next command.
  4. If there is a function that needs to be executed, the next command will be stored in a Stack in memory, when the function is finished, the content of Program Counter will be set to the address in the top of Stack.

Flag Register

Flag Register stores the sign(+/-/0) of the Accumulation Register.

There is a compare action when conditional/loop function appears. When the compare function is executed, subtraction action will happen, and the answer is store in the Flag Register, then the Program Counter will be updated to corresponding address.

Base and Index Registers

A base register and several index registers can form an array. The array is stored continuously.

Memory

Memory has tight relationship with with CPU, CPU will fetch the command and data from disk to memory, and write back the command and data to disk.

There is several kinds of memory.

Name Functions
RAM Can be read and wrote. Data will lose when power off
ROM Can only be read. Data won’t lose when power off
Cache It has high read and write speed. CPU will handle the cache firstly. If there is no required data, CPU will fetch data in RAM

Memory has power, address signal, data signal, control signal.

I/O devices

Disk

The program stored in disk must be loaded to memory to be executed.

The disk has the following parts

Name Function
Disk Cache It stores the repeated content that memory requires to read from disk. It could accelerate the read speed of memory
Virtual Memory It can provide a virtual continuous memory for the program when the memory doesn’t enough space. The content in the real memory and the virtual memory will be swapped when required

Physcially, the disk is divided into different sector, which is the unit to do the read and write actions to disk. A disk will include 512 byte normally.

Operate System

Operate system could get over the difference of computer hardware except CPU.

The program just needs to call the API(Application Programming Interface) in operate system, then operate could handle the I/O devices.

Operate system includes:

  • Control program. Includes the hardware control and program execution control
  • Programming language processor. Compilation.
  • Application. e.g. txt Editor

Reference

[1] WeChat article