Friday, January 8, 2016

How your computer works

In Von Neumann architecture we have:

#1. CPU (central processing units): Makes calculations, processing, control


The CPU contains:


The Data Path/Unit that and Control Path/Unit


which, more analytical contain:


Instruction register: Contains instructions

Instruction decoder: Signals to execute instructions

ALU: does the calculations/operations

Accumulator: Part of register that stores operands and results

Program counter: address of next instruction


Address register: address to be sent to memory

Data register: data exchange with memory
Internal registers: temporary storage

The instructions are executed sequentially in 2 phases.


The Fetch cycle: Fetch the next instruction from the Program Counter and store in the Instruction Register

The Execute Cycle: Read values from Registers, pass to ALU, write the result to the Register, store result in memory or send to Output device (I/O).

Machine language: Very basic instructions, fest execution, low level.

- Contains Operation Codes (opcodes)

Simpler definition from slides:


How does the CPU execute instructions ?


Fetch cycle: Instructions are stored in memory: must be fetched and

decoded

Execute cycle:

Decoded instruction must be executed.
Possibly operands must be fetched
Possibly operands must be written back

Example


To be executed: C=A+B


Step 1: store operands A and B in memory (2

addresses)

A: stored in memory cell 1000

B: stored in memory cell 1004

Step 2: find a memory space to store C

C: will be stored in memory cell 1008
Step 3: Translate the instruction in simple machine
instructions

LOAD 1000

ADD 1004
STORE 1008

Step 4: Load the program into memory


Program:
Memory address:  Command:
0000                              LOAD 1000
0001                               ADD 1004
0002                              STORE 1008
0003                              HALT
Memory:
1000                      234
1004                      980
1008                  1214


The computer starts with the first instruction:
memory address 0000

This is done by loading the program counter with 0000

________________________



Different CPUs have different instruction sets


Programs will not run on another CPU without conversion


We try really hard to speed up CPUs

=> Increasing Clock frequency  (e.g 2.4 GHz)

Speed doesn't depend only on clock frequency

Other ways to increase speed:
    Make broader data paths
    Making faster decoders in hardware
    Using parallelism (inside and outside CPU)

_____



Software development and stuff


Layers of organization/ languages


We write code in high level programming languages

the assembler converts it to (-> ASSEMBLY language)
operating system
machine language
that manipulates the hardware

Programming languages:

are instructions based on some vocabulary that the computer understands -through other software, see below-
Low level languages are close to the hardware, execute almost directly
High level languages are closer to human understanding



The Interpreter reads high level language,

produces instructions on a lower level and runs them
Fast writing, Slow execution
application: prototyping, short programs

The compiler translates high level language

to another program comprising only machine instructions
Slower development, debugging, linking required but fast execution
application: large, reliable programs, final program/app

How a program works:


Source code -> compiler -> object code -> linker  (+Object library) -> load module -> loader (+DLL) -> executable


Software development process


definition ->

specifications ->
functional analysis ->
technical design ->
implementation ->
testing ->
support
(don't learn by heart)

Good software development methods:

- Structured programming
- Object oriented programming: We create 'objects' of data, algorithms and even programs, we link and use the objects to build the final product.

That way we can write complex software in a reliable way.


Human mind can't handle as much complexity as some programs require.


____


Coding practices:

Compact code is harder to read & edit but often more efficient.


Software design can be optimized for performance (speed/memory) or maintainability 


The Operating system:
Manages the CPU

Manages the memory
Manages the I/O devices
Manages data
Manages your mother

Is kinda like the god

The ancestor of the operating system in those room size computers  is called 'monitor program'.

Monitor program was instructing simple processes that we given by people before.

And here we are now with 4K touchscreen miracles frying your balls.


Definition: Operation system is a set of programs designed to manage the computer esteem and interact with the user.


The OS controls the hardware and gives system calls. Users and applications use those system calls to interact with the hardware (screen, keyboard, speakers etc).


Part os the Operating System:
- Kernel

- Device drivers
- Graphical User Interface (GUI)

Structure: layered approach





Firmware is software 'hidden' inside a device (printers, graphic cards, webcams etc)


When 1 CPU has to manage many programs at the same time (which is always) the processes have to share CPU time.


The operating system decides that time allocation.


Processes switch all the time between CPU-use and I/O-use.


When a process uses an I/O device the CPU is free to run another process.


But processes need more time from the CPU than from the I/O so scheduling is important.


Scheduling:

When the OS changes processes that's called context switch. All processes that are ready to run have to wait for the CPU according to the schedule.

Algorithms to select a process:
- First Come First Served (FCFS)

- Shortest Job First (SJF)
- Time Sharing: Each process gets a fixed time period
- Combination/ priorities


When we have many cores (that's many CPUs) the OS decides which process to run on which CPU.


That's called load balancing.


In symmetric multiprocessors all CPUs are treated the same way.


In asymmetric multiprocessors CPUs have different jobs (like controlling, distributing, operations etc)


All this smart systematization requires itself work from the CPU and memory, duh.


But that's how we roll in CS, so suck it up


- - short break - - 


Memory Management:


When CPU runs several processes they all need a part of the memory.


Memory management:

- Allocates memory to processes
- Maps the addresses
- Ensures security: A process restricts its operations within its own memory

Principles:

- Memory partitions (segmentation)
- Paging (storing data in a secondary storage like HDD)
- Virtual memory (treating part of the HDD as RAM when RAM is not enough)

Memory partitions involve somethings called 'fence register' and 'relocation register', don't ask details.



I/O (Input/Output) management:


The OS doesn't have direct access to I/O devices but uses system calls.


Devices need drivers, which are software to get them communicate with the OS.


Each device needs its own driver.





Synchronization
Deadlock: Two or more competing actions wait for each other to finish, and thus neither ever does. (Like the awkward sidewalk don't-bump-on-the-stranger dance)




Managing the data:


We use a filesystem:

Stores all the data from files
retrieves files
Structures data in directories

Users and OS use the directory structure.


No comments:

Post a Comment