Lecture 3 - Computer Internals-Basics
Lecture 3 - Computer Internals-Basics
Microcontrollers
Lecture 3
Internals of a Computer - Basics
1
Recap from before
• We talked about CPU, busses, memory, IO
2
Figure 0-9. Inside the Computer
3
I/O
• I/O Peripherals= input or output or in/out devices
• Input: keyboard, mouse, pen, microphone, camera, touchpad for mouse, fingerprint
reader, proximity sensor, GPS signal reader, motion sensor, …
• Output: screen, speaker, printer, vibration motor, LCD display, drive motors (robotics),
…
• I/O: storage devices (USB, external HD), touch screen, internet modem, Ethernet card,
…
4
Data bus
• Carries information between CPU and memory and I/O devices
• The number of wires in the bus dictate the amount of data that can be moved at
one time
• Directly related to the CPU power
• 8-bit data bus (very old systems)
➔ 28 = 256 different values can be represented
• Currently in use: 32 bit (smart phones, microcontrollers, older PCs)
• 64 bit busses (most computers (personal or servers), some smart phones)
• 128 bit: Not yet – perhaps never. The costs and complexities outweigh the benefits
5
Address Bus
• Holds the address of a memory location or I/O device where data should be transferred
• n-bit address bus can access 2𝑛 possible locations
• Ex: 40-bit addressing: 240 = 220 2 = 1𝑀 2 = 1𝑇
• One terra locations with 40 bit address bus
• Byte-addressable storage: each location is one byte
• With 40 bits ➔1 Terra Bytes
• Word-Addressable storage: each location can store 1 word= 4 bytes
• With 40 bits ➔4 Terra Bytes
6
7
More on busses
• The address bus is a unidirectional bus
• CPU uses it only to send out addresses
• The data bus is bidirectional
• CPU uses it to receive or to send data
8
Storage devices
• Primary Storage: RAM and ROM
• Secondary Storage: Hard Disk, External Disk, USB Flash memory,
CD/DVD disc
9
ROM: Read Only Memory
• ROM holds information that is fixed and permanent
• Non-volatile memory
• Does not need electric current to maintain contents
• Examples of information stored
• tables for character patterns to be displayed
• Essential programs
• Bootup
• Basic input/output system (BIOS)
• Programs for hardware diagnosis
• Testing, finding the total amount of RAM installed
• Initial video displays
10
RAM: Random Access Memory
• Volatile memory
• Requires that electric voltage be maintained for information to stay
• RAM stores dynamic and temporary information
• Including program and data
• Different types of OS
• Applications (browser, wifi connection setup, audio, video, word processing)
• Whether it is programs or data, information should be loaded from an input (or
I/O) device into RAM to be processed by the CPU
11
Figure 0-10. Internal Organization of a Computer
12
General operation inside a computer
• Programs are made of instructions and data
• A programmer may write the following in a language: A= i+2;
• Identify the instructions and the data?
13
General operation inside a computer
• When the program is to be used, it has to be loaded from secondary storage
into RAM
• For CPU to execute them, it has to fetch them from memory and
“understand” what they are
• CPUs are equipped with resources such as the following:
14
CPU Internals: Registers
• Registers: very fast memory (fast flip flops – very close to ALU)
• Used to store information temporarily.
• Example: A=i+2; we need
• Two registers to hold the addresses of i and A
• One register for the value of i, 2 and A.
• Registers inside the CPU can be 8-bit, 16-bit, 32-bit, or even 64-bit registers
• the more and bigger the registers, the better the CPU
• The disadvantage of more and bigger registers is the increased cost, complexity and power
consumption of the CPU
15
CPU internals: ALU
• ALU (arithmetic/logic unit)
• Responsible for performing arithmetic and logic operations
• add, subtract, multiply, and divide,
• logic functions such as AND, OR, NOT, shift, …
16
CPU internals: PC (program counter)
• The program counter points to the address of the next instruction to be
executed
• As an instruction is executed, the program counter is properly incremented
to point to the address of the next instruction to be executed.
• The contents of the program counter are placed on the address bus to find
and fetch the desired instruction.
17
CPU internals: Instruction Decoder
• Programmers usually write in high-level languages
• C, java, javascript, C++, python,
• Each program gets stored in its language
• However, before a CPU is capable of executing it, the program must be
translated into the machine code instruction level that is CPU-dependent
• What the programmer writes is not what the executable version of the
program is!!
18
• Consider a simple instruction A=i+2
• This translates into CPU-level instructions to:
• Save the address of A into a register
• Read 2 (0000 0010) into a register
• Read the address of i (some binary address 0000 1101 0010 1100 ..)
• Read the contents inside that address (value of i) into a register (say i is 3: 0000 0011)
• Add (result of addition is 5= 0000 0101 is now in a temporary place)
• Store the result into the address of A
19
• Those instructions are encoded into a set of CPU-level instruction codes
• Each instruction has a unique binary code
• The instruction Decoder inside the CPU enables the control unit to
• enable the proper registers,
• perform the ALU operation,
• Perform the storage read/writes
• All in the correct sequence
20
• How many instructions (called instruction set) can a CPU understand?
• Is more better always?
• Advantages:
• can do more kinds of processing in hardware (faster than software)
• Can do more parallelized operations (example vector addition)
• Disadvantages of a CPU capable of understanding much more instructions
• requires more transistors to design
• More energy consumption
• More complexity (may even defeat the purpose – reaching to lower overall performance)
21
Figure 0-11. Internal Block Diagram of a CPU
22
Important example to understand
• Read the example on pages 17 and 18
• Numeric example of addressing, PC, bus, registers, ALU …
23