4.2 Computer Arithmetic and Memory System

This section focuses on computer arithmetic for performing arithmetic and logical operations, and the design and hierarchy of cache memory which is used to speed up data access.


1. Arithmetic and Logical Operations

Arithmetic and logical operations form the core of computer processing. These operations are carried out by the Arithmetic Logic Unit (ALU) of the CPU. Let's break down the various operations involved:

1.1 Arithmetic Operations

These operations perform mathematical calculations and are essential for tasks like addition, subtraction, multiplication, and division. The key arithmetic operations in computers include:

  • Addition: The most basic arithmetic operation. Computers typically perform addition using binary numbers. The half adder and full adder are digital circuits that help with binary addition.

    • Half Adder: Adds two single-bit numbers and produces a sum and carry.

    • Full Adder: Adds three bits (two operands and a carry input) and produces a sum and carry output.

  • Subtraction: Subtraction in binary is often performed using two's complement. This method allows subtraction to be performed using an adder circuit.

  • Multiplication: Multiplication is a repeated addition process. In binary, the process is similar to long multiplication in decimal, but instead of decimal digits, binary digits are used.

  • Division: Division is the inverse of multiplication. Binary division is performed by repeated subtraction (or a shift operation for optimization).

1.2 Logical Operations

Logical operations deal with the manipulation of individual bits. These operations are crucial for decision-making, control flows, and comparisons. Logical operations are executed by the ALU as well.

  • AND: The AND operation produces a 1 only if both operands are 1.

    • Example: 1010 AND 1100 = 1000

  • OR: The OR operation produces a 1 if at least one of the operands is 1.

    • Example: 1010 OR 1100 = 1110

  • XOR (Exclusive OR): The XOR operation produces a 1 if the operands are different.

    • Example: 1010 XOR 1100 = 0110

  • NOT: The NOT operation inverts the bits (flip 0 to 1, and 1 to 0).

    • Example: NOT 1010 = 0101

  • Shift Operations:

    • Left Shift (<<): Moves all bits to the left by a specified number of positions, effectively multiplying the value by 2 for each shift.

    • Right Shift (>>): Moves all bits to the right by a specified number of positions, effectively dividing the value by 2 for each shift.


2. Cache Memory Design and Hierarchy

Cache memory is a small, fast storage area located inside or near the CPU, used to store frequently accessed data or instructions. Cache memory reduces the time it takes to access data from main memory (RAM). The cache acts as an intermediary between the main memory and the CPU to speed up data retrieval.

2.1 Cache Memory Design

Cache memory operates using several design principles:

  • Fast Access: Cache memory is much faster than main memory (RAM), typically using static RAM (SRAM) instead of dynamic RAM (DRAM).

  • Small Size: Cache memory is smaller in size compared to main memory due to the high cost of SRAM. However, it provides much faster access.

  • Levels of Cache: Modern computers use multiple levels of cache, typically L1, L2, and sometimes L3, each with different speeds and sizes.

    • L1 Cache: The Level 1 (L1) cache is the smallest and fastest cache. It is located directly on the CPU chip.

    • L2 Cache: The Level 2 (L2) cache is larger than the L1 cache and is usually located on the CPU chip or close to it. It stores data that is less frequently used than the L1 cache.

    • L3 Cache: The Level 3 (L3) cache is even larger and slower than L1 and L2 caches. It is typically shared by multiple CPU cores.

2.2 Cache Memory Hierarchy

The hierarchy of cache memory is designed to balance speed and size. The CPU first looks for data in the L1 cache, then the L2 cache, and finally the L3 cache if it’s present. If the data is not found in any cache, the CPU will access the main memory (RAM), which is much slower.

  • Cache Hit: A cache hit occurs when the requested data is found in the cache. This results in a fast access time.

  • Cache Miss: A cache miss occurs when the requested data is not found in the cache. In this case, the CPU must access the slower main memory, leading to higher latency.

2.3 Cache Mapping Techniques

To efficiently manage which data is stored in the cache, several cache mapping techniques are used:

  • Direct-Mapped Cache: Each block of main memory is mapped to exactly one cache line. This is simple and fast but can result in cache conflicts.

  • Fully Associative Cache: Any block of main memory can be stored in any cache line. This technique offers more flexibility but requires more complex hardware.

  • Set-Associative Cache: Combines elements of both direct-mapped and fully associative caches. The cache is divided into sets, and each set can store multiple blocks.

2.4 Cache Replacement Policies

When the cache is full and new data needs to be stored, a replacement policy determines which data to evict. Common policies include:

  • Least Recently Used (LRU): The least recently used data is replaced first.

  • First-In, First-Out (FIFO): The oldest data in the cache is replaced first.

  • Random Replacement: A randomly selected block is replaced.


Conclusion

  • Arithmetic and Logical Operations:

    • Arithmetic operations (addition, subtraction, multiplication, division) are the core functions of the ALU. Logical operations (AND, OR, XOR, NOT) deal with manipulating individual bits in a binary representation.

    • Shift operations, such as left and right shifts, are used for efficient arithmetic manipulations.

  • Cache Memory:

    • Cache memory is a small, fast storage used to reduce the time it takes to access data from slower main memory. It exists in multiple levels (L1, L2, L3) and works based on the concept of cache hits and misses.

    • Efficient cache management involves mapping techniques (direct-mapped, fully associative, set-associative) and replacement policies (LRU, FIFO, Random).

Last updated