Introduction to Computer Architecture

Welcome to this introductory guide on Computer Architecture. This document is designed for university students beginning their journey into the principles of programming and computer science. Understanding computer architecture is fundamental because it explains how the hardware you write software for actually works. It's the bridge between the physical world of electronics and the abstract world of code.

1. History of Computing Machines

The concept of automated computation is not new. It stretches back to antiquity with devices like the abacus. However, the modern computer's journey began with mechanical devices and evolved through electronics to the microscopic integrated circuits we use today.

The Mechanical Era

Early pioneers like Blaise Pascal (Pascaline, 1642) and Gottfried Wilhelm Leibniz (Stepped Reckoner, 1672) created mechanical calculators that could perform basic arithmetic. However, it was Charles Babbage who envisioned a programmable machine. He is often considered the "father of the computer" for his designs of the Difference Engine and the more ambitious Analytical Engine in the 19th century. The Analytical Engine was a mechanical general-purpose computer that possessed many features of modern computers, including an Arithmetic Logic Unit (ALU), control flow in the form of conditional branching and loops, and integrated memory. Working with him, Ada Lovelace is credited with writing the first algorithm intended to be processed by such a machine, making her the first computer programmer.

The Electronic Revolution

The 20th century saw the transition from mechanical to electronic computing. Key milestones include:

  • ENIAC (Electronic Numerical Integrator and Computer): Completed in 1945, it was among the first general-purpose electronic computers. It was massive, filling a large room, and had to be physically rewired to change its program.
  • The Von Neumann Architecture: A pivotal moment came when John von Neumann proposed a computer architecture where both program instructions and data are stored in the same memory. This "stored-program computer" concept is the basis for nearly all modern computers. It consists of a Central Processing Unit (CPU), a memory unit, and input/output devices.

Hierarchy and Necessity

The development of computing machines has been driven by necessity: the need for faster calculations for military applications (e.g., artillery firing tables), scientific research, and eventually, business and consumer applications. This led to a hierarchy of advancements:

  1. Vacuum Tubes: Enabled the first electronic computers but were bulky, unreliable, and consumed immense power.
  2. Transistors: Invented in 1947, they replaced vacuum tubes. They were smaller, faster, more reliable, and consumed less power. This marked the "second generation" of computers.
  3. Integrated Circuits (ICs): In the 1960s, engineers found a way to place many transistors onto a single silicon chip. This miniaturization drastically reduced cost and size while increasing power, leading to the "third generation".
  4. Microprocessors: The 1970s saw the development of the microprocessor, an entire CPU on a single chip, which ushered in the era of personal computers (the "fourth generation").

2. The Meaning of Computer Software

If hardware represents the physical components of a computer system, software is the set of instructions, data, or programs used to operate computers and execute specific tasks. It is the intangible part of the computer that tells the hardware what to do and how to do it.

"Hardware is the stage, software is the play."

Software is broadly divided into two categories:

  • System Software: This software manages the computer hardware and provides a platform for application software to run. The most important piece of system software is the Operating System (OS), like Windows, macOS, or Linux. Other examples include device drivers and utility software.
  • Application Software: This is the software designed to perform specific tasks for the end-user. Examples include web browsers, word processors, games, and database applications. The code you write as a programmer is typically application software.

The relationship is layered: your application software talks to the operating system, and the operating system talks to the hardware. This abstraction makes programming much easier, as you don't need to know the exact electronic details of the hardware you're running on.

3. Number Systems

Computers do not understand human language or even the decimal numbers we use daily. At their core, they operate on a binary system. Understanding different number systems and how to convert between them is crucial.

General Representation of a Number

Any number can be represented in a base (or radix) \(b\) system. The value of a number is given by the polynomial formula: \[ D = \sum_{i=-m}^{n-1} d_i \cdot b^i \] Where \(d_i\) is the digit at position \(i\), \(b\) is the base, \(n\) is the number of integer digits, and \(m\) is the number of fractional digits.

Proof of the Formula (by Example)

This formula is the definition of positional notation. Consider the decimal number 37.5. Here, \(b=10\), \(n=2\), \(m=1\). The digits are \(d_1=3, d_0=7, d_{-1}=5\). Expanding the sum: \[ D = (d_1 \cdot 10^1) + (d_0 \cdot 10^0) + (d_{-1} \cdot 10^{-1}) \] \[ D = (3 \cdot 10) + (7 \cdot 1) + (5 \cdot 0.1) = 30 + 7 + 0.5 = 37.5 \] This demonstrates that the formula is a generalized way of expressing how the position of a digit determines its value.

Conversion Algorithms

Decimal Integer to Any Base \(b\)

The algorithm uses successive division. Let \(D\) be the decimal integer. \[ D = q_0 \cdot b + r_0 \] Where \(q_0\) is the quotient and \(r_0\) is the remainder (which will be the least significant digit, \(d_0\)). Next, we divide the quotient \(q_0\): \[ q_0 = q_1 \cdot b + r_1 \] Here, \(r_1\) is the next digit, \(d_1\). We continue this until the quotient becomes 0.

Proof of the Algorithm

By substituting the expressions for the quotients back into the first equation: \[ D = (q_1 \cdot b + r_1) \cdot b + r_0 = q_1 \cdot b^2 + r_1 \cdot b + r_0 \] Substituting again, \(q_1 = q_2 \cdot b + r_2\): \[ D = (q_2 \cdot b + r_2) \cdot b^2 + r_1 \cdot b + r_0 = q_2 \cdot b^3 + r_2 \cdot b^2 + r_1 \cdot b + r_0 \] This continues until the last quotient is zero. The final form is: \[ D = r_k \cdot b^k + \dots + r_2 \cdot b^2 + r_1 \cdot b^1 + r_0 \cdot b^0 \] This is the polynomial representation of the number in base \(b\), where the digits \(d_i\) are the remainders \(r_i\). Since we find \(r_0\) first, the remainders must be read in reverse order.

Decimal Fraction to Any Base \(b\)

The algorithm uses successive multiplication. Let \(F\) be the decimal fraction. We want to find the digits \(d_{-1}, d_{-2}, \dots\) in the representation: \[ F = d_{-1}b^{-1} + d_{-2}b^{-2} + d_{-3}b^{-3} + \dots \]

Proof of the Algorithm

Multiply the entire equation by \(b\): \[ F \cdot b = d_{-1} + d_{-2}b^{-1} + d_{-3}b^{-2} + \dots \] The integer part of this result is \(d_{-1}\), the first fractional digit. The new fractional part is \(F_1 = d_{-2}b^{-1} + d_{-3}b^{-2} + \dots\). We repeat the process: \[ F_1 \cdot b = d_{-2} + d_{-3}b^{-1} + \dots \] The integer part is now \(d_{-2}\). This process is repeated to find successive digits until the fractional part becomes zero or the desired precision is reached.

5. Memory

Computer memory is any physical device capable of storing information temporarily or permanently. In the context of the Von Neumann architecture, memory holds both program instructions and data. Modern systems use a memory hierarchy to balance speed, cost, and capacity.

The hierarchy is effective due to the Principle of Locality:

  • Temporal Locality: If an item is accessed, it is likely to be accessed again soon (e.g., loops in code).
  • Spatial Locality: If an item is accessed, items with nearby memory addresses are likely to be accessed soon (e.g., sequential array elements).

This principle allows a small, fast cache to significantly speed up access to a large, slow main memory.

LevelTypical SizeAccess TimeManaged By
CPU Registers~1 KB< 1 nsCompiler
L1/L2 Cache~16 KB - 4 MB~1-10 nsHardware
L3 Cache~8 MB - 64 MB~10-30 nsHardware
Main Memory (RAM)~4 GB - 64 GB~50-100 nsOperating System
Secondary Storage (SSD)~256 GB - 4 TB~50-150 µsOS / User

6. Representation of Integers

Unsigned Integers

A number is represented by its straightforward binary equivalent. With \(n\) bits, you can represent integers in the range \([0, 2^n - 1]\).

Signed Integers: Two's Complement

The most common method is Two's Complement. The most significant bit (MSB) is the sign bit (0 for positive, 1 for negative). With \(n\) bits, the range is \([-2^{n-1}, 2^{n-1} - 1]\).

Proof of the Range

  • Maximum Value: The largest positive number has a sign bit of 0, followed by \(n-1\) ones: \(011\dots1\). This is a geometric series: \(2^{n-2} + 2^{n-3} + \dots + 2^1 + 2^0\). The sum of this series is \( \frac{2^{n-1}-1}{2-1} = 2^{n-1} - 1 \).
  • Minimum Value: The most negative number is represented by \(100\dots0\). In two's complement, the weight of the MSB is negative. So, the value is \(-1 \cdot 2^{n-1} + 0 \cdot 2^{n-2} + \dots + 0 \cdot 2^0 = -2^{n-1}\).
  • Value of -1: The representation for -1 is \(111\dots1\). The value is \(-2^{n-1} + (2^{n-2} + \dots + 2^0) = -2^{n-1} + (2^{n-1} - 1) = -1\). This confirms the system's consistency.

Mathematical Foundation and Proof of Negation

Two's complement works based on modular arithmetic. For an n-bit system, arithmetic is performed modulo \(2^n\). The two's complement of a positive number \(x\) is defined as \(TC(x) = 2^n - x\).

The "invert and add one" shortcut is derived from this definition. The one's complement (inverting the bits) of \(x\) is equivalent to subtracting \(x\) from the largest \(n\)-bit unsigned number, which is \(2^n - 1\). \[ \text{One's Complement of } x = (2^n - 1) - x \] If we add 1 to the one's complement: \[ ((2^n - 1) - x) + 1 = 2^n - x = TC(x) \] This proves that the "invert and add one" algorithm correctly computes the two's complement of a number.

Sign Extension

To convert an \(n\)-bit two's complement number to an \(m\)-bit number where \(m > n\), you must copy the sign bit to fill the new, higher-order bits. For a positive number, you pad with 0s. For a negative number, you pad with 1s.

7. Representation of Decimal Numbers

Floating-Point Numbers (IEEE 754 Standard)

This standard represents decimal numbers in a form of scientific notation. The value is: \[ \text{Value} = (-1)^S \times (1.M) \times 2^{(E - \text{Bias})} \]

The standard defines several formats. The two most common are:

  • Single-Precision (32-bit): 1 sign bit (S), 8 exponent bits (E), 23 mantissa bits (M). Bias = 127.
  • Double-Precision (64-bit): 1 sign bit (S), 11 exponent bits (E), 52 mantissa bits (M). Bias = 1023.

Special Values

The standard reserves certain exponent values to represent special numbers:

Exponent (E)Mantissa (M)Represents
All 0s0Zero (\(\pm 0\))
All 0sNon-zeroDenormalized Number (very small)
1 to (Max-1)AnyNormalized Number
All 1s0Infinity (\(\pm \infty\))
All 1sNon-zeroNot a Number (NaN)

This allows for representing outcomes of invalid operations, like \(1/0\) (Infinity) or \(\sqrt{-1}\) (NaN).

Practice Questions

1.

What was the key innovation of the Von Neumann architecture, and how did it differ from earlier computer designs like the ENIAC?

2.

Explain the purpose of the memory hierarchy and the Principle of Locality that makes it effective.

3.

Convert the decimal number 188 to its 8-bit binary representation.

4.

Convert the binary number 1010101101 to both hexadecimal and decimal.

5.

What is the primary advantage of using Two's Complement to represent signed integers in computer systems? Explain from a hardware perspective.

6.

Find the 8-bit Two's Complement representation of the decimal number -85.

7.

What decimal number is represented by the 8-bit Two's Complement binary number 11010110?

8.

Explain the difference between system software and application software. Provide two examples of each.

9.

Why is hexadecimal representation often used by programmers to view memory contents instead of binary?

10.

Convert the hexadecimal number 4CF to binary and decimal.

11.

An 8-bit memory location stores the value 11110000. What is its decimal value if it is interpreted as (a) an unsigned integer, and (b) a Two's Complement signed integer?

12.

What does it mean for a floating-point number to be "Not a Number" (NaN)? Provide an example of a mathematical operation that would result in NaN.

13.

Describe the roles of transistors and integrated circuits in the evolution of modern computers.

14.

Perform the following binary addition: 01101011 + 00110110. Assume the numbers are 8-bit unsigned integers.

15.

Using 8-bit Two's Complement arithmetic, calculate 45 - 20 by converting the numbers to binary and adding them (i.e., calculate 45 + (-20)).

16.

A 4-bit system represents the number -3 as 1101 in two's complement. How would this number be represented in an 8-bit system using sign extension?

Solutions & Explanations

1. The Von Neumann Architecture

The key innovation of the Von Neumann architecture was the stored-program concept. This meant that both the program instructions (the code) and the data the program operates on are stored in the same memory unit. In earlier designs like the ENIAC, the "program" was physically wired into the machine. To change the program, technicians had to manually unplug and replug cables, a process that could take days. The stored-program concept made computers far more flexible and powerful, as programs could be loaded, modified, and executed from memory just like data.

2. The Memory Hierarchy & Locality

The memory hierarchy exists to create a balance between speed, cost, and capacity. The Principle of Locality makes it work. It has two forms: Temporal Locality (if you use something, you'll likely use it again soon) and Spatial Locality (if you use something, you'll likely use data near it soon). Because of this predictable behavior, a small, fast, expensive cache can hold the data the CPU is most likely to need, making the large, slow, cheap main memory seem much faster than it is. This provides high performance at a reasonable cost.

3. Convert 188 (Decimal) to Binary

We use successive division by 2.

188 / 2 = 94 remainder 0
94  / 2 = 47 remainder 0
47  / 2 = 23 remainder 1
23  / 2 = 11 remainder 1
11  / 2 = 5  remainder 1
5   / 2 = 2  remainder 1
2   / 2 = 1  remainder 0
1   / 2 = 0  remainder 1

Reading the remainders from bottom to top, the result is 10111100.

4. Convert 1010101101 (Binary)

To Hexadecimal: Group into sets of four from the right.

Binary: 0010 1010 1101
  0010 = 2
  1010 = A
  1101 = D

The hexadecimal representation is 2AD.

To Decimal: Sum the powers of 2 for each '1' bit.

  1 * 2^9 = 512
+ 1 * 2^7 = 128
+ 1 * 2^5 = 32
+ 1 * 2^3 = 8
+ 1 * 2^2 = 4
+ 1 * 2^0 = 1
----------------
Total = 685

The decimal representation is 685.

5. Advantage of Two's Complement

The primary advantage of Two's Complement is that it simplifies hardware logic. With this system, the CPU's Arithmetic Logic Unit (ALU) does not need separate circuitry for subtraction. Subtraction can be performed using the exact same addition circuits. For example, calculating A - B is equivalent to calculating A + (-B). The ALU simply finds the two's complement of B and adds it to A. This reduces the complexity and cost of the hardware.

6. Find 8-bit Two's Complement of -85

First, find the binary representation of positive 85.

85 decimal = 01010101 binary (in 8 bits)

1. Invert the bits:
   10101010

2. Add 1:
   10101010
+         1
-----------
   10101011

The 8-bit Two's Complement of -85 is 10101011.

7. Convert 11010110 (Two's Complement) to Decimal

The most significant bit is 1, so the number is negative. To find its magnitude, we take the two's complement of the number itself.

Binary: 11010110

1. Invert the bits:
   00101001

2. Add 1:
   00101010

Now, we convert this positive binary result to decimal: \(32 + 8 + 2 = 42\). Since the original number was negative, the final answer is -42.

8. System vs. Application Software

System Software manages the computer's hardware and provides essential services. It acts as an intermediary between the hardware and the application software. Examples:
- Operating Systems (Windows, Linux)
- Device Drivers (e.g., for a printer or graphics card)

Application Software is designed to perform specific tasks for the user. It runs "on top of" the system software. Examples:
- Web Browsers (Chrome, Firefox)
- Word Processors (Microsoft Word, Google Docs)

9. Why Use Hexadecimal?

Hexadecimal is used as a human-friendly shorthand for binary. Binary numbers can become very long and difficult to read, making it easy to make mistakes. Since one hexadecimal digit perfectly corresponds to a group of four binary digits (a nibble), it's very easy and efficient to convert between the two. This makes hexadecimal a compact and less error-prone way for programmers to read and write low-level data like memory addresses or raw file contents.

10. Convert 4CF (Hexadecimal)

To Binary: Convert each hex digit to its 4-bit binary equivalent.

4 = 0100
C = 1100
F = 1111

The binary representation is 010011001111 (or 10011001111).

To Decimal: Sum the powers of 16.

  (4 * 16^2) + (12 * 16^1) + (15 * 16^0)
= (4 * 256) + 192 + 15
= 1024 + 192 + 15 = 1231

The decimal representation is 1231.

11. Interpret 11110000

(a) As an unsigned integer:

128 + 64 + 32 + 16 + 0 + 0 + 0 + 0 = 240

The value is 240.

(b) As a Two's Complement signed integer:

The leading bit is 1, so it's negative. Find its magnitude:

Original: 11110000
Invert:   00001111
Add 1:    00010000

00010000 in binary is 16 in decimal. Since the original was negative, the value is -16.

12. IEEE 754 "Not a Number" (NaN)

NaN stands for "Not a Number" and is a special value in the IEEE 754 standard used to represent the result of an undefined or unrepresentable mathematical operation. For example, calculating the square root of a negative number (\(\sqrt{-1}\)) or dividing zero by zero (\(0/0\)) would produce NaN. It helps prevent a program from crashing by providing a specific value for these invalid outcomes.

13. Role of Transistors and ICs

Transistors were the replacement for bulky, power-hungry, and unreliable vacuum tubes. They function as electronic switches and are the fundamental building blocks of all modern digital electronics. Their invention made computers smaller, faster, more reliable, and more energy-efficient, marking the second generation of computing.

Integrated Circuits (ICs) were the next major leap. An IC places hundreds, thousands, or now billions of transistors onto a single tiny silicon chip. This massive miniaturization allowed for the creation of a microprocessor (an entire CPU on one chip), which in turn led to the personal computer revolution. ICs drastically reduced the cost and size of electronics while exponentially increasing their power and complexity.

14. Binary Addition

  11  111  <- Carries
  01101011  (107 in decimal)
+ 00110110  (54 in decimal)
-----------
  10100001  (161 in decimal)

The result is 10100001.

15. Two's Complement Subtraction (45 - 20)

We calculate 45 + (-20).

Step 1: Convert 45 to 8-bit binary.

45 = 32 + 8 + 4 + 1 = 00101101

Step 2: Find the 8-bit Two's Complement of -20.

Positive 20 = 16 + 4 = 00010100
Invert:                11101011
Add 1:                 11101100  (This is -20)

Step 3: Add the two binary numbers.

  1111  1   <- Carries
   00101101  (45)
+  11101100  (-20)
-----------
(1)00011001

We discard the final carry bit that goes beyond the 8th position. The result is 00011001.

Converting this back to decimal: 16 + 8 + 1 = 25. This is the correct answer.

16. Sign Extension

To extend an \(n\)-bit two's complement number to an \(m\)-bit number (\(m > n\)), you must copy the sign bit into all the new bit positions to the left.

The number is 1101. The sign bit (the MSB) is 1. To extend it from 4 bits to 8 bits, we add four bits to the left and fill them with the sign bit.

Original (4-bit): 1101
Sign bit is 1.
Extended (8-bit): 11111101

The 8-bit representation is 11111101.