It covers the basics of computers, including their components, such as the hard drive, RAM, graphics card, motherboard, and processor. The role of the CPU in the execution of instructions and the structure of computer programs are described. The concept of binary, decimal and hexadecimal number systems, programming languages and operating systems is also introduced. In addition, it explains how applications interact with the OS and how games are part of this process. Readers will learn about the basics of creating and working with computer games, as well as how they are integrated into computer systems.
A typical computer consists of several connected components. Among the most important:
Hard drive
OZP
Video Map
Motherboard
CPU
If you remove the side of the desktop computer, the parts can be placed in this configuration:
For our purposes, we’ll only cover the first four components briefly, and then focus on the CPU in the next section:
Hard drives are responsible for storing large files such as photos, executables, or system files.
RAM stores data that needs quick access. Data is loaded into the RAM from the hard disk.
Video cards are responsible for displaying graphics on the monitor.
Motherboards connect all these components together and allow them to exchange data.
The CPU is the brain of the computer. He is responsible for following instructions. These instructions are simplified and vary by architecture. For example, an instruction might add two numbers. To speed up execution time, the CPU has several special areas where it can store and modify data. They are called registers.
All computer programs consist of a series of instructions. As we discussed above, an instruction is simple and usually performs only one action. For example, below are some instructions that can be found in most architectures:
Add the two numbers
Subtract two numbers
Compare the two numbers
Move number to memory partition (RAM)
Go to another section of code
Computer programs are developed based on these simple instructions strung together. For example, a simple calculator might look like this:
mov eax, 5 mov ebx, 4 add eax, ebx
The first instruction (mov) moves the value 5 into the eax register. The second moves the value 4 into the ebx register. The add instruction then adds eax and ebx and puts the result back into eax.
Computer programs are collections of instructions. Programs are responsible for receiving a value (input) and then creating a value (output) based on the received value.
For example, one simple program might take a number as input, increment the number by 1, and then move it to output. It might look like this:
mov eax, input add eax, 1 mov output, eax
A more complex program would have many of these simple programs “inside”. In this context, these simple internal programs are called functions. Functions, like programs, take input and produce output. For example, we could make our previous program a function that does the same thing. It might look like this:
function add(input): mov eax, input add eax, 1 mov output, eax
We could also create another function that performs a similar operation. For example, we could write a function to decrement a number by 1:
function subtract(input): mov eax, input sub eax, 1 mov output, eax
These two functions (addition and subtraction) can then be used to create a more complex program. This new program will take a number and increment or decrement it. Two inputs will be required:
Number
A mathematical operation, in this case addition (+) or subtraction (-)
This new program will be longer and have two different ways to complete it. They will be explained after the code:
function add(input): mov eax, input add eax, 1 mov output, eax function subtract(input): mov eax, input sub eax, 1 mov output, eax cmp operation, '-' je subtract_number add(number) exit subtract_number: subtract(number) exit
This code has two functions at the top. As we discussed, they take an input and then add or subtract 1 from the input to get the output. The cmp instruction compares two values. In this case, it compares the operation type received as input and the value coded in the program – . If these values are equal, we jump to (or jump to) another section of code (je = jump if equal).
If the operation is – , we jump to the code that subtracts 1 from the number. Otherwise, we continue the program and add 1 to the number before exiting.
Comparing numbers and then moving to another code depending on their value is called branching. Branching is a key component of developing complex programs that can respond to different inputs. For example, a game often has branches for each direction the player can move.
In essence, processors are circuits. Electricity either flows in the circles (on) or there is no electricity (off). These two states can be represented by the binary number system (or base 2). In a base-2 system, you have two possible values: 0 and 1. An example of a binary number is 1101.
We are familiar with the decimal number system (or base 10), which has 10 possible values: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. An example of a decimal number is 126. This number can be represented in in a more explicit format as:
We can represent the binary number above (1101) in the same format. However, we will replace 10 with 2 since we are going from a base 10 system to a base 2 system:
Binary numbers can quickly become unwieldy when they need to represent larger values. For example, the binary representation of the decimal number 250 is 11111010.
Computing usually uses hexadecimal (base 16) numbers to represent these larger binary numbers. Hexadecimal numbers are usually prefixed with the identifier 0x and have sixteen possible values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. An example of a hexadecimal number is 0xA1D .
Instructions are represented as numbers, just like all other data on a computer. These numbers are known as operation codes, often shortened to operation codes. Opcodes are architecture dependent. The CPU knows each opcode and what it needs to do when it encounters each one. Operation codes are usually represented in hexadecimal format. For example, if an Intel processor encounters 0xE9, it knows it needs to execute a jmp (jump) instruction.
Early computers required programs to be written in operation codes. This is obviously difficult to do, especially for more complex programs. Then, variants of the assembly language were adopted, which allowed writing instructions. They are similar to the examples we wrote above. Assembly language is easier to read than just opcodes, but it is still difficult to develop complex programs.
Several high-level languages such as FORTRAN, C, and C++ have been developed to improve the development experience. These languages are easy to read and include flow control operations such as if and else * conditions. For example, below is our increment/decrement program in C. In C, int refers to an integer or an integer (-1, 0, 1, or 2 are examples).
int add(int input) { return input + 1; } int subtract(int input) { return input - 1; } if(operation == '-') { subtract(number); } else { add(number); }
All of these high-level languages are compiled into assembly. A traditional assembler then converts this assembly into opcodes that the CPU can understand.
Writing programs for communication with equipment is a time-consuming and complex process. To run our zoom program, we would also have to write code to handle keystrokes on the keyboard, display graphics on the monitor, create character sets so we can represent letters and numbers, and communicate with RAM and hard disk. . To make it easier to develop programs, operating systems were created. They contain code that can already handle these hardware functions. They also have a few standard features that are commonly used, such as copying data from one location to another.
The three main operating systems still in use today are Windows, Linux, and MacOS. They all have different libraries and methods of communicating with the hardware. This is why programs written for Windows do not work on Linux.
Operating systems need a way to determine how to handle data when the user selects it. If the data is a photo, the operating system wants to open a specific application (such as Paint) to view the photo. Similarly, if the data is the program itself, the operating system must pass it to the CPU for execution.
Each operating system handles execution in a unique way. In Linux, a special execute permission is set for a regular file. In Windows, programs are formatted in a special way that Windows knows how to parse. This is called the PE format, or Portable Executable. The PE format has several sections, such as a .text section for storing program code and a .data section for storing variables.
With all that out of the way, we can finally discuss the games. Games are just programs. In Windows, they are formatted in PE format, identical to any other program. They contain a .text section that contains the program code consisting of opcodes. These opcodes are then executed by the CPU, and the operating system displays the resulting graphics and processes input such as keystrokes.