Essential Computer Science: Binary, OS Kernel, Von Neumann, Assembly
Classified in Computers
Written on in English with a size of 53.68 KB
Binary Operations and Number Systems
Bitwise Shift Operations
Left Shift
The left shift operator (<<
) shifts bits to the left, filling the vacated positions on the right with zeros. This is equivalent to multiplying the number by powers of two.
Right Shift
The right shift operator (>>
) shifts bits to the right. There are two types:
- Logical Right Shift: Fills the vacated positions on the left with zeros.
- Arithmetic Right Shift: Fills the vacated positions on the left with the most significant bit (sign bit) of the original number, preserving the sign for signed integers.
Decimal to Binary Conversion
To convert a decimal number to binary, repeatedly divide the decimal number by 2. Record the remainder (which will be either 0 or 1) from right to left. Continue this process with the quotient until the quotient becomes 0. The sequence of remainders, read from last to first, forms the binary representation.
Hexadecimal Conversion
To convert a binary number to hexadecimal, split the binary number into groups of four bits, starting from the right. If the leftmost group has fewer than four bits, pad it with leading zeros. Then, find the hexadecimal representation for each 4-bit group.
Example: 1111001010
(binary)
- Split into groups of 4:
0011 1100 1010
(padded with leading zeros) - Convert each group:
0011
=3
,1100
=C
,1010
=A
- Result:
3CA
(hexadecimal)
Binary Arithmetic
Binary Addition
Line up the binary numbers one on top of the other and add downwards, similar to decimal addition. If the sum of bits in a column is 2 or more, carry over the excess to the next column to the left.
Example: 1011 + 1110 = 11001
Binary Multiplication
Binary multiplication is similar to elementary school multiplication. Line up the numbers, multiply across, and then add the partial products.
Example: 1011 x 1101 = 10001111
Understanding Overflow
For an unsigned number: Overflow occurs when the last carry cannot be accommodated within the fixed number of bits, meaning the result exceeds the maximum representable value.
For a signed number: Overflow occurs when the result of an arithmetic operation exceeds the range of values that can be represented by the given number of bits. Specifically:
- The sum of two positive numbers results in a negative number.
- The sum of two negative numbers results in a positive number (often referred to as underflow in this context, though it's a type of overflow).
Operating System Kernel Fundamentals
File Descriptors and System Calls
Standard File Descriptors
In Unix-like operating systems, standard file descriptors are pre-assigned integer values:
stdin
(Standard Input) =0
stdout
(Standard Output) =1
stderr
(Standard Error) =2
When an open
system call is successful, the value returned is the lowest-numbered unused file descriptor available to the process.
File Descriptor Table Independence
Each process maintains its own independent file descriptor table. However, system-wide tables like the I-node Table and the Open File Table are shared and managed by the kernel.
System Calls vs. Library Calls
System calls are often slower than library calls because they require a context switch from user mode to kernel mode. This transition is necessary for the CPU to access protected kernel memory and execute privileged instructions.
Example: Changing directories using cd ~/UMASS/CICS/CS250
might involve system calls to navigate the file system.
Kernel Abstractions
The operating system kernel provides fundamental abstractions that simplify interaction with hardware and manage system resources. Key abstractions include:
- Files: An abstraction for persistent storage.
- Processes: An abstraction for a running program, including its memory space and execution context.
- Virtual Memory: An abstraction that provides each process with its own isolated memory space, independent of physical memory.
User Space to Kernel Space Data Transfer
To pass data or requests from user space (where applications run) to kernel space (where the operating system kernel resides), applications must use system calls. System calls act as an interface, allowing user programs to request services from the kernel in a controlled and secure manner.
Von Neumann Architecture Principles
Pipeline vs. Scalar Execution
The Von Neumann architecture is a computer architecture based on a stored-program concept where instruction data and program data are stored in the same memory space. This architecture supports different execution models:
- Scalar Execution: Processes one instruction at a time.
- Pipelined Execution: Overlaps the execution of multiple instructions, allowing different stages of instruction processing (fetch, decode, execute, write-back) to occur concurrently.
Core Components of Von Neumann Architecture
The fundamental components of a Von Neumann architecture include:
Memory
A single, unified storage unit for both data and instructions, each accessible by a unique address.
Instruction Register
A CPU register that stores the instruction currently being executed or decoded.
Decoder
A component that interprets the instruction from the instruction register and generates the necessary control signals to execute the instruction.
ALU (Arithmetic Logic Unit)
The digital circuit within the CPU that performs arithmetic operations (like addition, subtraction) and logical operations (like AND, OR, NOT).
Challenges with Control Instructions in Pipelining
Control instructions (e.g., conditional branches like cmpl
or jmp
) can pose challenges for pipelined execution. When a branch instruction is encountered, the pipeline might need to be flushed if the branch target is not correctly predicted, leading to stalls and reduced performance.
Introduction to Assembly Language
Assembly language is a low-level programming language that has a strong correspondence between its statements and the architecture's machine code instructions. It provides direct control over hardware components and is often used for performance-critical applications, device drivers, and embedded systems.