Professional Documents
Culture Documents
Go Computer
Go Computer
Go Computer
com/chap-1-programming-a-computer
• RAM/ROM
• CPU
3 Introduction
This book is about Go. Before jumping into our main subject, you need to know some basic knowledge about computers.
Experienced programmers can skip this chapter. Beginners should take some time to study it.
Your programs will run on hardware. Knowing how your hardware is working may improve the design of your programs.
Firstly we will describe the main components of a computer. Then we will see what a program is and how the machine handles it.
The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.
1 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
• The memory unit (MU) where data and programs are stored.
◦ For instance, we can store into the memory unit the grades of a college class. We can also hold a program that will compute the
class’s average grade.
• The arithmetic and logic unit (ALU). Its role is to perform arithmetic and logical operations on data stored into the memory unit.
This unit can perform, for instance, additions, incrementations, decrementations, which are called operations. In general, each
operation requires two operands and output a result.
◦ Let’s say we want to add 5 and 4. Those two numbers are the operands. The result of this operation is 9. Operands are loaded
from the memory unit. The ALU is an electrical circuitry that is designed to execute operations.
• The input and output unit (I/OU) will be in charge of loading data into the memory unit from an input device. This unit also sends
data from the memory unit to an output device.
◦ An input device is, for example, the touchpad of your computer, your keyboard, your mouse.
• The control unit (CU) will receive instructions from programs and will control the activity of the other units.
The four hardware components represent a schematic view of the computer’s components.
5 Memory
A computer is composed of two types of memory :
• Volatile
• Non Volatile
• RAM (Random Access Memory). This type of storage requires electric power to persist data. When you turn your computer off, the
memory contained in this type of storage will be erased. The operating system and the programs you use will be loaded into this
memory. This type of memory is volatile.
• ROM (Read-Only Memory). This is a memory that contains data necessary for the computer to run correctly. This kind of memory is
not volatile (when you turn the computer off, it will not be erased). It’s designed to be only readable and not updated by the system.
Read and writes to this type of memory is slow compared to the RAM.
Some hard drives sequentially access memory. The system should respect a particular sequence. Respecting this access sequence takes a
longer time than a random access mode. Note that some hard drives allow random memory access.
SSD (Solid-State Drives) are not constructed like that. There is no magnetic head neither magnetic disks. Instead, data is stored in flash
memory cells. Data access is quicker on that kind of disk. Note that SSD also costs more than traditional electromagnetic hard drives.
6 CPU
CPU is the initials of Central Processing Unit. The CPU is also denoted processor. The CPU contains :
2 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
The CPU will be responsible for executing the instructions given by a program. For instance, the program can instruct to perform an
addition between two numbers. Those numbers will be retrieved from the memory unit and passed to the ALU. The program might also
require performing an I/O operation like reading data from the hard drive and loading it into the RAM for further processing. The CPU will
execute those instructions.
7 What is a program?
To make computers do something, we have to feed them with precise instructions. This set of instructions is called “program”.
Following a more official definition, a program is “a combination of computer instructions and data definitions that enable computer
hardware to compute”[@institute1990ieee].
Let’s take an example. Imagine a program that asks the user to type two numbers. The program adds those numbers, and the result is then
displayed on the monitor. The instructions that have to be written are :
1. Output “Please type your first number and press enter” on the monitor.
2. When a number is typed and the “Enter” key is pressed on the keyboard, store the number into memory. Let’s denote A this number.
3. Output “Please type your second number and press enter” on the monitor.
4. When a number is typed and the “Enter” key is pressed on the keyboard, store the number into memory. Let’s denote B this number.
5. Send to the ALU the two numbers (A and B ) and the addition opcode and store the result into memory.
• I/O operations : retrieve numbers stored into memory, store numbers into memory from an the input device (the keyboard), load
data from memory, and display it to the user.
We have here a set of instructions that are written in plain English. The machine does not understand English sentences. Those sentences
need to be translated to a language that the machine understands. What is this language?
The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.
• Low level
• High level
Low-level programming languages are closer to the processing unit’s instructions. Higher-level languages provide constructs that make
them easier to learn and to use on a day-to-day basis.
Some high-level languages are compiled, others are interpreted, and some are in between. We will see in the next sections what those two
terms mean.
3 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
It’s possible to write computer programs directly into machine language. However, this is not easy.
To create a program in assembly language, the developer will write instruction to one or several files. Those files are named source files.
// assembly code
mov eax,1
int 0x80
Those two lines will perform a system call that will close the program (the “1” represent the system call number that means “exit the
program”). Note that assembly language is different from machine to machine. We say that it’s machine-specific.
An assembler is used to convert the source files written in an assembly language to object code files. We say that we assemble the
program. The linker will then transform those object code files into an executable file. An executable file contains all the computer’s
necessary instructions to launch the program.
4 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
os.Exit(1)
// C Code
exit(1)
// Java Code
System.exit(1);
In this example, we do not have to move a number into a register; we use the languages constructs (functions, packages, methods,
variables, types ...). The objective of this book is to give you precise and concise definitions of those tools to build Go applications.
High-level programs are also written to files. Files are named “source files”. Generally, programming languages require adding a specific
extension to the filename. For Go programs we will add “.go” At the end of each file that we will write. In PHP the extension is “.php”.
When source files are written, the program that they define cannot be executed immediately. The source file needs to be compiled by
using a compiler. The compiler will transform source files into an executable. The compiler is also a program. Go is part of the compiled
language family.
Go is a compiled language
9 Test yourself
9.1 Questions
1. Where are programs stored?
5 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
2. Reading data from a hard drive is slower than reading data from RAM. True or false?
6. Which program transforms code written assembly language into object code?
9.2 Answers
1. Where are programs stored?
1. True. Fetching and writing data to the RAM is blazing fast, whereas accessing data stored into hard drives generally takes
longer.
3. A computer user can write ROM? True or false?
1. False. This type of memory can only be read. It is used to store the OS (Operating system)
4. What are the two types of memory?
1. The assembler will take as input assembly language code and generate machine code.
7. Which program transforms object code into an executable file?
1. The linker
8. Give two advantages of high-level languages compared to low-level languages?
2. The code will not be specific to the technical architecture of a machine. We say that the code is portable.
10 Key takeaways
• At the macro-level, a computer is composed of :
◦ An Input and Output Unit (IOU): to manage input devices and output devices.
◦ A Control Unit (CU) will manage the MU, ALU, and IOU following the instruction given by the program executed
• CPU means Central Processing Unit (also called processor or microprocessor) is composed of the ALU and CU.
• Programming languages are composed of words and characters that must be ordered following specified rules.
6 of 7 02/01/2023, 01:57
Programming A Computer - Practical Go Lessons https://www.practical-go-lessons.com/chap-1-programming-a-computer
• Machine language and assembly language are low-level. The instructions written in those languages are closely linked to the
hardware organization and capabilities. They provide little abstractions.
Bibliography
• [institute1990ieee] Electrical, Institute of, and Electronics Engineers. 1990. “IEEE Standard Glossary of Software Engineering
Terminology: Approved September 28, 1990, IEEE Standards Board.” In. Inst. of Electrical; Electronics Engineers.
Previous Next
Table of contents
Did you spot an error ? Want to give me feedback ? Here is the feedback page! ×
Newsletter:
Like what you read ? Subscribe to the newsletter.
@ my@email.com
Practical Go Lessons
By Maximilien Andile
Copyright (c) 2023
Follow me Contents
Posts
Book
Support the author Video Tutorial
About
The author
Legal Notice
Feedback
Buy paper or digital copy
Terms and Conditions
7 of 7 02/01/2023, 01:57