How A Computer Program Works

Home /

Table of Contents

In this tutorial, we’ll go over some very high-level concepts about how a computer program works. Please keep in mind that we have simplified them in this tutorial. The purpose of this tutorial is to expand your computer vocabulary and introduce you to programming jargon so that you can proceed. You can read more about computer architecture in other books. This tutorial is not meant to be a reference.

The following quote may give you some insight into what programming really is.

To program a computer to add 1 & 1 and get 2, first you have to tell it what “1” is; then you have to tell it what “addition” is; then you have to tell it what “equals” is; then you have to tell it what “2” is. Then you can tell it that 1+1=2 & it will do it perfectly every time, infinitely faster than we can.

A computer program, in general, is a collection of software that runs on the hardware. We’re assuming you’re familiar with hardware and software. Nonetheless, we’ll go over them briefly to refresh your memory.

What is Hardware?

Computer hardware is the physical parts of the computer. 

Typically, software directs hardware to carry out any command or instruction. A functional computing system consists of a combination of hardware and software, though there are systems that only use hardware.

What Are The Physical Parts?

  •      Case
  •      Central Processing Unit or CPU
  •      Random Access Memory or RAM
  •      Monitor
  •      Mouse
  •      Keyboard
  •      Computer Data Storage(HDD,SSD etc)
  •      Graphics Card
  •      Sound Card
  •      Speakers
  •      Motherboard
oOw8dXNj9YM4uRRyr5IgkMiEv8NW2SckpgHeCpnxTpW5w9LZOsJxDPuq s15 q1NWLn2t4bhtBjXyYgdBJVfxDNi - How A Computer Program Works

You do not need to be an expert on them or understand how they work. It is sufficient to have a basic understanding of them. Hardware is so named because it is difficult or rigid to change. A piece of hardware’s components is rarely interchangeable. However, you can upgrade your hardware. The addition of new or additional hardware to a computer that improves its performance expands its capacity or adds new features is referred to as an upgrade in computer hardware.

To improve performance, a user could, for example, perform a hardware upgrade to replace the hard drive with a faster one or a Solid State Drive (SSD). The user can also add more Random Access Memory (RAM) so that the computer can store and retrieve temporary data more quickly. To fully utilize USB 3.0 devices, the user can add a USB 3.0 expansion card or upgrade the GPU for cleaner, more advanced graphics or more monitors. For older computers to meet requirements, such hardware upgrades may be required.

The following are some of the physical components of a personal computer:

Motherboard

The main component of a Computer is the motherboard. Hence the name. It is the main physical part. It is a board with integrated circuitry (You don't have to know the detail) that connects other parts of the computer including - CPU, RAM, Disk Drives(HDD,SSD,CD,DVD, or any other) as well as any peripherals connected via the ports or expansion slots.
4q88pLkGziDi3x3Feqk77bhC2sQjG3451LKXiWxAziMQCuu9VDOJjASN5h bjZlWc8JZbnsjPCseow8B0m4kRbcN2FgAoXt6ihZmqt3hgPSqyPqMNANML6Ul9VKBzL50ZWM84Hd27WI4PbClCbjqsQ - How A Computer Program Works

CPU

CPU is the brain of the computer. It performs most of the calculations which enables a computer to function. But we can not directly give program instructions to the CPU ourselves. So from where does a CPU get the program instructions and data required to execute the instructions? The answer is from the RAM. First the CPU loads program instructions from RAM, then interprets them as well as process them, and after processing send back results so that the relevant components can carry out the instructions.
qIcrH9nzLE3HbIm8Lxj6RIWbX5nZKgH9i6NiuIjNVLDzZHFjWzTNA6NE55jd4muU0aaabJplH29Kjn9BMbsqV98L5Lz9qNw jKKf1jguxaP5UUVnIqaSGYZ6im E9v6vL5pnF2G7fV0NLHr1Y3MAbg - How A Computer Program Works

RAM

RAM is another important component that is directly integrated into the motherboard. It is referred to as the system's main memory. Access times are much faster because data is accessed randomly rather than sequentially, as it is on a CD or hard drive. RAM stores both our program code and data. The CPU actively accesses the RAM for data. When we open a web browser to surf the internet, for example, the instructions to run the web browser and the necessary data are first stored in RAM. They are actively accessed, interpreted, and processed by the CPU. The data and instructions are kept in RAM until the Web Browser is closed.
RZye5woExWOU8oA2EISXKjxy - How A Computer Program Works

Input Devices

Input devices enable users to enter data into the system or control its operation. Most personal computers include a mouse and keyboard. Touchpads are more commonly found on laptop computers. Webcams, microphones, joysticks, and image scanners are examples of other input devices.
an2L3litfWrMO07oJslymdWM5uPR5RQLjmc5NvbdQYhYyrbw afQK crVorNbQ NuNwzHKCHcYKf7jLCMQ1OfYQArH6SjRYJntcSlM9gx0EEE6OfNPCzFydASC krj6lrbhfdIBVPOA oDnOcu6Dng - How A Computer Program Works

Output Devices

Human senses are central to the design of output devices. Monitors, for example, display text that can be read, whereas speakers produce sound that can be heard. Printers and Braille embossers are examples of such devices.
TKytBwwtZ8 DXhglOU369Pzt6zXBKPUlpLdufSCOrNvd6G5cmcJRFyU46jlLsCyO t2VBPP29ep6SuG8Ix6ymWkd3 UWIv8g7sxgsr YDzXrMBfkfBdQsUR04j 8Jhc4jSIOTTNL88Anr iuGbBpbg - How A Computer Program Works
In short, the CPU does all the data processing and calculations, Input devices are used to give input data when required, RAM stores data and instructions  which are actively accessed and processed by CPU, CPU may present us with some output using the output devices.

What is Software?

Software is the set of instructions that can be used and run by the hardware. Hardware is typically directed by the software to execute any command or instructions. A usable computing system is a combination of both hardware and software.  

RAM is the main memory. It plays a vital role to run any and every program in our system. So we are going to discuss RAM a little bit more so you can have a clear understanding of how RAM works.

How Does the RAM Work?

The Operating System(as it is software), applications programs, and data that are currently being used are kept in RAM so that the computer’s processor can quickly reach them. Random Access memory is volatile, which means that data is retained in RAM as long as the Computer is on. When we turn off the computer that data is lost. When we reboot the computer the OS and other files are reloaded into RAM, usually from an HDD or SSD. RAM can not store permanently as it is volatile.

Any storage location, commonly known as memory address of a RAM can be accessed directly. Hence this memory component is called Random Access Memory or RAM.

If it does not make any sense to you right now do not worry. We have not yet told you why we need to address memory location in the RAM. We will explain this now. To further illustrate the concept of RAM, consider RAM as a set of boxes.

mgH2KY22sp4ecQY9tfG09i39W1 vQs7 YxPiYNH3Vw3cv9hOxtmLQhSX9Ryqw4IrWIl GHmSEBUKOw40irQKKmrW10itokmHEjeZNe5 pBJfMmsdpFF1cO4gBXT6s42y2BF71M9Vc9qK1iLJ7 0s4w - How A Computer Program Works

 

There are many such boxes in RAM that determine its SIZE.

Id8yl4tiYADS fNEpGgfcAwfoTyjdH5pCBP - How A Computer Program Works

Typically there are billions of such boxes in a RAM.

A box can only hold a Boolean value. A Boolean or bool is a data type in computer science that has two possible values: true or false. It takes its name from the English mathematician and logician George Boole. The algebraic and logical systems that he devised are widely used in all modern digital computers. We all talk about data type later in the All About Data Types tutorial. 
But we have told you over and over again that computers only understand numeric format or numbers. So how does it interpret true or false. It does so by considering true as 1 and false as 0. So any box in the RAM can store either a 1 or 0 as its value. A box can only store one value at a time. It can not store both the 0 and 1 at the same time in a specific box. If we try to do so the previous stored value will be substituted by the new value. The following figure demonstrates this.
0 g7P9 0tVfAoErcKiqyoDtpN9glxtJXIl1eTGvueePXnHcXaUMGebNlSDXatpwaFUmbB2hnjBFS SVjSYwRZAi2F9DRC54f5Vs4 hysWfBVih8sycnIhZ17zBVe9qyDZ4u3WiRjegm4LeW5czVkrA - How A Computer Program Works

How Each RAM Cell is Addressed?

Each box has a unique address associated with it. This address can be found by counting across the columns and down the rows.
gN2eb9 XR5OxkpC54JX txb - How A Computer Program Works

 

A set of ram boxes is called an array, and each box is known as a cell.
DNFgxE5gjAz6OcQwlXBAJ7PljHzT Yhkjqxv31uwqHCE8XFFNP15Xg5MZqqnb3QrJj7PDqnZHMp4QNvYJa02YhrvXNM0Zi4lLh6EIVNH ACMcdUftoL EL5ZTsJYvInF795Wicbanc7cXV1vbXiJEg - How A Computer Program Works

To find a specific cell in the RAM, the RAM controller does the following:

Sends the column and row address down a thin electrical line etched into the chip. Each row and column in a RAM array has its own address line. Any data that’s read flows back on a separate line.

REMEMBER each box is called a cell or a memory cell. It is the fundamental building block of Computer memory. The memory cell is an electronic circuit that stores one BIT of binary information and it must be set to store a logic 1 (high voltage level) and reset to store a logic 0 (low voltage level). Until a set/reset operation is performed the memory cell’s value is maintained/stored. The value in the memory cell can be accessed by reading it.

What is A “BIT”?

Now let us discuss the bit. It is the most basic unit of information in computing and digital communications. The word bit is a combination of “bi” from “binary” and “t” from “digit”. What bit actually represents is a logical state with one of two possible values – in our case either 0 or 1. It can not represent both at the same time.

What is A “BYTE”?

A contiguous group of binary digits is commonly called a bit string, a bit vector, or a single-dimensional (or multi-dimensional) bit array.

25 srzFUYVhxCe CDh0mYpvLWD54BLo4BMhTGHMDeRFZQcCRUbtFcQ1E6YtttTOYRL7KUPgnhT70tGeCoD TIoy21JWD1QSavI6FIlykwRMjUX v0YV9fwyR xyil8HhdtYYIucC5W12lDMuw LU2w - How A Computer Program Works

A group of eight binary digits is called one byte, but historically the size of the byte is not strictly defined. Frequently, half, full, double, and quadruple words consist of a number of bytes which is a low power of two. A string of four binary digits is a nibble.

What is the Reason for Grouping Contiguous Binary Digits?

Let us first realize why we should take contiguous binary digits. Why does the need arise in the very first place? We know that computers only understand numbers and that too of one format only, called binary format. This format consists of only two digits. 0 and 1. We derive different numbers using the combinations of 0 and 1. In a binary number system, data is stored in bits. A bit can only hold one of the two values – either a 0 or a 1 at a time. A bit is the basic unit of information. We rarely work with information one bit at a time, as they are very small and do not give us significant insight. While considering alone bits can only give us information like – true or false, yes or no. But when we group some specific number of bits together as a single unit, the information they can hold significantly increases.

Let us go back to our analogy of a set of boxes.

image 1 - How A Computer Program Works

There are 16 boxes in this set of boxes. Each box can contain a Boolean value: either a 0 or a 1.

image 2 - How A Computer Program Works

When we get the value from the box, only one box at a time, the box can not provide us with much information as the capability of storage of a box is very limited. But if we group the boxes – like the first four boxes consisting of a group, boxes 5 through 8 consisting of another group, and so on. Now using this idea of a group combination of boxes we enhance the capability of storing significantly. In real-life applications, bits are assembled into a group of 8 to form a  byte. In other words, a byte consists of 8 contiguous bits. Though the standard number of bits in a byte is 8 digits long, that number may vary from system to system depending on the hardware. In java, A byte is 8 bits long. The memory address is addressed using byte values.

image 3 - How A Computer Program Works

Let us consider our box analogy again. We now take 8 boxes to make a group. In the first box, we can only store one of the two numbers/information either a 0 or 1 true/false. Now let us consider the first two boxes. Each box can store or hold two possible values, so the total number of positive values that two boxes can store is 4 possible values. This is also true for any group of two boxes. Now take us to a contiguous group of eight boxes or bits.

image 4 - How A Computer Program Works

There exists a mathematical formula for how many possible values a set of bits can store. The formula is

            2^n

where n is the number of bits in a set of bits(in our box analogy it is the number of boxes in a group of boxes). A byte has 8 bits or 8 binary digits. So it can store 2^8=256 different values. They are called byte values as each of the combinations of 8 bits represents a single byte.  A byte can store a numerical value between 0 and 255 while considering only positive numbers. If we also consider negative numbers they can hold a numerical value between -127 and +127 (inclusive). This numerical value is calculated using binary number to decimal number conversion. This is not discussed here as it is out of the scope of this tutorial. We address memory cells using byte values.

Historically Bytes are used to represent characters. The reason behind this is simple – Bytes contain enough information to store a single character.

When we consider 2-Byte memory or in simple words an assembly of a group of 16 contiguous bits instead of 8 contiguous bits, we call this arrangement – a Short. A Short can store 2^16 different values ranging from -32768 to +32767 when we are considering negative values.

image 1 - How A Computer Program Works

When we consider 4-Byte memory or in simple words an assembly of a group of 32 contiguous bits instead of 8 contiguous bits, we call this arrangement – an Integer. An integer can store 2^32 different values ranging from -2,147,483,648 to 2,147,483,647 when we are considering negative values.

image 5 - How A Computer Program Works

When we consider 8-Byte memory or in simple words an assembly of a group of 64 contiguous bits instead of 8 contiguous bits, we call this arrangement – a Long. A Long can store 2^64 different values ranging from -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1) when we are considering negative values.

image 5 - How A Computer Program Works
image 5 - How A Computer Program Works
Keep this in mind a byte is 8 times a bit, a short is double a byte, an integer is double a short, and a long is double a integer.
  • A kilobyte or KB consists of 1024 times a byte
  • A megabyte or MB consists of 1024 times a kilobyte
  • A gigabyte or GB consists of 1024 times a megabyte
  • A terabyte or TB consists of 1024 times a gigabyte
Share The Tutorial With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Check Our Ebook for This Online Course

Advanced topics are covered in this ebook with many practical examples.

Other Recommended Article