Overview of Computer Architecture
Although software is thought of as being separate from hardware, the fact is that software exists in the larger context of hardware. Having an understanding of the environment within which your code will be running is useful. Specifically when dealing with certain bugs relating to memory, or understanding how values are changed physically with different operations in your code.
We will now consider a few pieces of hardware involved in the running and processing of our code. We will look at:
- The Motherboard
- Hard Drives
- The CPU
1. The Motherboard
The motherboard is the central hub (think "Grand Central Station") of the computer. It connects together all the various hardware components, and is the conduit along which all other components receive power, and along which data runs. A diagram of the general layout of a motherboard is presented below:
The main components I would like to highlight (which are boxed in red in the diagram) are the CPU Socket, the Memory sockets and the IDE/SATA sockets for the Hard Drive(s). These sockets are where the various components are connected to the motherboard. If you look closely at the picture above, you will see thin silver lines running throughout the motherboard. These are the conduits (or circuits) along which instructions/data/signals are sent between the various components on the motherboard and to connecting devices.
2. Hard Drives
Hard drives are the devices on which your files are stored. Older Hard drives connected to the motherboard using a wide IDE cable, whereas newer hard drives make use of the thinner Sata cable. Because of the existence of these two technologies for hard drives, often motherboards (as is the case in the image above) will have connectors for both types.
The hard drive contains disk platters, which store data as 1's and 0's and are accessed via the actuator, which reads in the bits of data. Read more about the mechanisms of a hard drive on wikipedia at: http://en.wikipedia.org/wiki/Hard_disk_drive
Here we have a short video clip to watch the Hard Drive in action:
A computer may have more than one hard drive. The first hard drive (Primary Drive) will contain the Operating System, whereas the remaining drives do not necessarily have to contain any Operating System (although they may), and are usually used for storing files and folders.
When we write code and save that code in text files. Those text files are stored as 1's and 0's on the surface of the Hard Drive disk platter. These 1's and 0's are called "binary" and we will be discussing that in a future module.
Memory, specifically Primary Memory, is a high-speed temporary storage area. One or more of these memory modules (see picture above) will plug directly into the memory slots on the motherboard. Because of the technology used and the close proximity to the motherboard, data stored inside these memory modules are able to be accessed much faster than data stored on the hard drive. Thus, it is often the case that when a program is running, it will be copied from the hard drive, and loaded into memory temporarily whilst running so that its execution will be faster.
Inside memory (also known as RAM or Random Access Memory), different locations in the storage area are referenced by an address system. So, if a piece of data needs to be moved into memory, then the address of a vacant piece of memory is located and the data is moved to memory at that address. You can think about this like houses on a street, and people as pieces of data. As people go in and out of various houses in a street, you can refer to their location by the house number on that street. Similarly, you can refer to the location of data in memory by the address of that area in memory.
Note: This idea of memory addresses is important to understand for future sections. If more clarity is needed, please read through the wikipedia article: http://en.wikipedia.org/wiki/Memory_address
4. The CPU
The CPU (Central Processing Unit) is often referred to as "the brain of the computer". This is true to an extent, as it is responsible for processing and manipulating pieces of data. Inside the CPU, there are micro circuits for every kind of mathematical and logical operation (such as add, subtract, and so on). When your code runs, each instruction to the computer is broken down into a simple set of instructions (see Assembly), where each of these simplistic instructions corresponds to one of the micro circuits inside the CPU.
As your code is running, the instructions and values are then moved from memory (remember the instructions or code was originally on the hard drive and then was moved into memory) into a special kind of memory attached adjacent to the CPU called Cache. Because cache is very close, physically, to the CPU, it is even faster to access data stored in Cache than to access data stored in memory. However, the amount of data that can be stored in cache is much smaller than the amount of data stored in memory, which is in turn much smaller than the amount of data able to be stored on the hard drive.
Depending on the instructions the CPU is running, the result of the microcircuit operations may then be transferred back into memory to update values previously stored, or to store new values. These values are managed programmatically in your code as variables, which we will discuss next.
Here are some exercises to help familiarize you with your hardware.
- Describe the difference between the terms: "PC", "Laptop", and "Tablet PC" and "Desktop PC".
- Is your PC using 32-bit, or 64-bit architecture, and how did you find this out?
- How much physical memory does your PC have, and how did you find this out?
- How much free space do you have on your primary hard drive, and how did you find this out?