CPU and Input and Output Devices

CPU and Input and Output Devices

In conclusion of the introduction to hardware for programming, I want to talk about the CPU and the devices that we use in programming to enter data into the program and display the output of the programs. Of course, we are dealing with much more comprehensive issues in the discussion of programming, but this series of posts so far were written to create a simple understanding of hardware and, in fact, to create an insight in you. What I want to convey to you is that before programming, you should fully understand the available tools and your limitations. I want to convey to you that first and foremost, understand the system and then, using all the tools at your disposal, design the software and use the appropriate algorithm to achieve the optimal program that meets your needs.

CPU

The CPU has two roles: first, coordinating all the operations of the computer and second, performing computational and logical operations on data.
The CPU follows the program instructions to determine the type and order of operations. Then it sends coordination control signals to other components of the computer. For example, if an instruction performs a data reception task, the CPU sends a coordination control signal to the input device.

So, to process a program stored in main memory, the CPU fetches each instruction in order, determines the operation of that instruction, and then retrieves the data necessary to execute that instruction. In the next step, the CPU performs the main processing or processes on the retrieved data and finally stores the results of the processing in main memory.
Of course, as I mentioned in previous posts, I usually mean the RAM in the computer.

In addition to these operations and coordination, the CPU can also perform arithmetic operations such as addition, subtraction, multiplication, and division. It is also able to compare the contents of two memory cells and make a decision based on this comparison and its result.

Input and Output Devices (I/O)

In programming, we use I/O devices to communicate with the computer. In simple terms, I/O devices allow us to enter our data into the computer for calculations and see the output of the calculations.

The keyboard is one of our input devices in programming and the screen is also usually our output device. What happens is that when you press a key on the keyboard, the character you want is sent to memory and simultaneously printed on the screen at the cursor position.

Always keep in mind that the screen temporarily prints information on the screen. When an image is cleared from the screen, that image is lost, so it is natural that if you want to have a printed copy of it, it is better to print it using a printer or, in our own words, send it to an output device such as a printer.