OS & System Programming Flashcards
Revise This Module for Exams
What is Von Neumann Architecture also known as?
Stored-program computer
What is a Stored-program computer
A computer that stores program instructions in memory
Does Reprogramming require any change in hardware?
NO
What are the Architecture 3 main components?
- CPU
- Memory
- I/0 Interface
What is the CPU?
Heart of the Computing System
Includes:
- Control Unit (CU)
- Arithmetic Logic Unit (ALU)
What is Memory?
The computer’s memory stores program data & instructions
What I/O Interfaces?
They are used to receive or send information from the connection.
- Connected devices are called peripheral devices.
How are programs executed on Von Neumann Computers?
- Program is stored in memory
- Translated in Machine code
1) CU understands that data needs to be provided by the user.
2) Data is Read from input device & bought to the CPU
What is ALU?
Union of the circuits for performing Arithmetic & Logical Operations
What is CU role?
Responsible for step-by-step execution of instructions during a program execution.
What are Registers?
- Small storage element, located close to ALU
- Used as temporary storage during computation
- ALU can read & write from Registers very fast
What are the advantages of using Registers?
- Fast, does computation in Registers without constantly storing new values
- Improves processing speed
- Allows us to read data from memory once(Registers Store Immediate Data)
- Reading Registers tend to have zero-time overhead
Does CPU need Registers?
No, can use memory to store all the data
How long does it take to read/write data?
4ms
How long does Arithmetic take?
1ms
How is Memory Organised?
- Memory consists of small ‘cells’
- Each cell stores a small piece of data
- cells have addresses 0 to n-1
Memory Access?
- Read & Stores operations, CPU generates addresses
- Memory Management unit reads or writes from/to memory location
Decimal Representation :
- Base 10 system
- 0-9 are digits
Binary Representation:
- Base 2 System
- digits are 0&1
- digits called ‘bits’
- 8 ‘bits’ are called a ‘byte’
eg: 1110 = 14
Hexadecimal Representation:
- Base 16 System
- Digits: 0,12,3,4,5,6,7,8, A,B, C,D, E, F
e.g : A3B = 2114
What is the General Structure of a C Program?
- Execution begins at main()
- Header of file contains imports / pre-defined libraries
Examples of Control Flows?
- if statements: conditional computation
- if-else : Multiple Branching
- Switch Statements
- For / while/ do-while loops
Basic if statement implementation?
if (condition) {
statement;
}
Example of if-else
if (condition) {
statement;
}
else if (condition) {
statement
}
else{
statement
}
Example of Switch
switch (condition){
case (A):
statement
break;
case (B):
statement
break;
default:
statement
break;
}
Example of for loop
for (int i; i < MAXRANGE; i++){
statement
}
Example of Conditional While Loop
while(condition){
statement
// Change condition or Not
}
Example of Infinite While Loop
while(1){
statement
// Can break the code
}
Example of Do While Loop
do {
statement
}
while (condition){
statement
}
// RUN THE CODE ONCE AND THEN DOES IT AGAIN IN WHILE LOOP
What does ‘continue;’ do?
- skips the current iteration
- Jumps to the beginning of the next iteration
What does ‘break;’ do?
- Comes out of the loop and the loop gets terminated.
Arrays in C?
int a[4] ; // Uninsialised
int b[3] = {2,3,4}
- Fixed-size
- Sequential collection of elements of the same type
What are errors with Arrays in C?
- Compiler does not check array limit
- Memory Protection was violated and the program crashed due to segmentation fault
How are Undefined Behaviours created?
- Out-of-bound access
- Signed int overflow
- Div by Zero
- UB hit, the program can theoretically do anything
Example of Function?
return_type func_name (arguments ) {
local variables declared
statements
return data of type declared
}
Format of printf() function:
printf(“%format”,variable_name);
format:
The Type for Variable name
What does printf() do?
- Prints values into the standard ouptut
- Defined in stdio.h library
What does scanf() do?
- Receive inputs from keyboards
- Defined in stdio.h library
Format of scanf() function:
scanf(“%format”,&variableName);
- format is placeholder for Data type
- &variableName is a pointer to store input into memory
What is a String?
-String of chars is a 1D array of chars
-Terminated by ‘\0’ == Null Char
- Can be read by scanf