Table of contents
During the course, first we consider the digital computer as a black box,⇒ and then we will gradually go into detail about its internal workings. Finally, we shall see the computer as a white box, getting a clear picture of the fundamental aspects of how the computer works.
In order to achieve our goals, we shall discuss, among others, the following topics:
- Introduction to computers. The computer as an information processing machine (black box model, data vs. information etc.). Basic IT concepts.⇒
- digital computers
- computer systems; computer achitecture
- computer hardware
- early computers; electronic computers
- computer software
- computer applications
- Number systems, conversion rules and algorithms (through examples and computer programs). The concept and basic characteristics of algorithms, and ways of how we can express them.⇒
- number or numeral systems; positional notation
- decimal, binary and hexadecimal notation
- using simple JS programs to describe algorithms
- Conversion algorithms. Description of the presented algorithms using short programs.⇒
- Data representation, formats, operations and related algorithms (numerical, character, logical or Boolean types, etc.).⇒
- binary representation of unsigned integers
- two's complement representation of integers
- binary coded decimal (BCD) representation of integers
- floating-point notation of real numbers
Click here to test your skills in performing the various conversion and data representation algorithms.Click here to test your skills in creating simple JavaScript programs to describe algorithms.You can use an online JavaScript interpreter to try the JS example programs presented in the material:
Online JavaScript Interpreter by Peter Jipsen, Chapman University (January 2013).
http://math.chapman.edu/~jipsen/js/ (2020-11-19)Note: If the link above does not work for some reason, please use the link here.
The flowchart of JavaScript programs can be displayed using the following web application:
Live code editor. Created by Bogdan Lyashenko.
https://bogdan-lyashenko.github.io/js-code-to-svg-flowchart/docs/live-editor/index.html (2022-10-02)Important note: the flowchart does not represent the 'for' loop correctly, so it is worth rewriting 'for' loops into 'while' loops before displaying the flowchart of the program.
Click here to test your skills in practising the above exercises.
Revision questions and exercises
(1) Write a JavaScript program to convert a binary integer to a decimal one! (e.g. x="10001110"2 → y=14210)
(2) Write a JavaScript program to convert a binary fraction to a decimal one! (e.g. x="0.101"2 → y=0.62510)
(3) Write a JavaScript program to convert a hexadecimal number to a decimal one! (e.g. x="13A"16 → y=31410)
(4) Write a JavaScript program to convert a decimal number to a hexadecimal one! (e.g. x=31410 → y="13A"16)
(5) Write a JavaScript program to convert a decimal number to a binary one calling a function named 'dec2bin'. The result of the conversion has to be displayed in the right-side panel of the JS interpreter (and not in a console). (e.g. x=14210 → y="10001110"2)
Important remark: without writing the function and displaying the result the exercise cannot be accepted.(6) Write a JavaScript program to convert a decimal number to a hexadecimal one calling a function named 'dec2hex'. The result of the conversion has to be displayed in the right-side panel of the JS interpreter (and not in a console). (e.g. x=14210 → y="8D"16)
Important remark: without writing the function and displaying the result the exercise cannot be accepted.(7) Write a JavaScript program to convert a decimal fraction to a binary one having a maximum of 6 fractional digits, and writes the result of the conversion in the right-side panel of the JS interpreter. (e.g. x=0.687510 → y="0.1011"2 or x=0.4510 → y="0.011100"2)
(8) Write a JavaScript program to convert a decimal integer between 0 and 255 to an 8-bit long binary number, and writes the result of the conversion in the right-side panel of the JS interpreter. (e.g. x=1510 → y="00001111"2)
(9) Write a JavaScript program to convert a hexadecimal integer to a decimal number, and writes the result of the conversion in the right-side panel of the JS interpreter. (e.g. x=8E16 → y="14210)
Table of contents
The main purpose of the course is to answer the following question: how can we design and implement a digital computer?
Logic circuits representing various logical functions can be easily designed using the following web applications:
Logic Gate Simulator | Academo.org – Free, interactive, education.
https://academo.org/demos/logic-gate-simulator/ (2022-11-19)simulator.io - Build and simulate logic circuits.
https://simulator.io/ (2022-11-19)Click here to test your skills in practising the above exercises.
Exercises
- creating truth tables manually⇒ and with simple JavaScript programs⇒
- proving logical laws or tautologies (e.g. distributivity, absorption, de Morgan laws etc.⇒) by creating truth tables
- using logical laws or tautologies for transforming given logical expressions into equivalent ones
- creating the disjunctive formal form (DNF) of logical functions given by truth tables⇒
- creating and testing logic circuits from logic gates⇒ in order to implement a given logical expression⇒
Revision questions and exercises
(1) Illustrate the block diagram of the computer and write down the main hardware units of the computer.
(2) Illustrate the fetch-execute cycle with a diagram, and write down the stages of the fetch-execute cycle with special emphasis of the use of the instruction pointer and the instruction register.
(3) Write an assembly program to add two integers together (e.g. 7 and 14) and set the return value to the sum!
(4) Write down the content of the stack frame of the above program relative to the stack pointer and the basic pointer!
(5) Answer the following questions:
- Which command should be used for compiling the 'asm.s' assembly program to an executable file using 'gcc'?
- List the most important parts of the CPU and their functions.
- List the available registers of the x64 architecture.
- What is a stack, what instructions can you use to operate it, and what role does the stack pointer play in those operations?
(6) Write an assembly program to subtract two integers (e.g. 15 and 9) by using a function called 'subtract'. Calculate the difference of the given numbers by calling the 'subtract' function and set the return value of the 'main' function to the difference (e.g. 15−9=6)!
(7) Write down the content of the stack frame of the above program just before the stack frame of the 'subtract' function has been destroyed (i.e. two instructions before the 'ret' instruction of the 'subtract' function) relative to the stack pointer and the basic pointer!
(8) Write an assembly program to add three integers (e.g. 15, -3 and 9) with a stack frame of 56 bytes, and set the return value of the 'main' function to the sum (e.g. 15−3+9=21)!
(9) Write down the content of the stack frame of the above program just before the stack frame of the 'main' function has been destroyed (i.e. two instructions before the 'ret' instruction of the 'main' function) relative to the stack pointer and the basic pointer!
(10) Answer the following questions:
- Which command should be used for compiling the 'asm.c' C language source file to an assembly program using 'gcc'?
- How does the content of the instruction pointer and the instruction register change in the fetch-execute cycle?
- List the available general-purpose registers of the x64 architecture.
- Write some assembly instructions to perform the following operations:
- store two integers in the stack (e.g. 2 and 3)
- retrieve the two stored integers from the top of the stack
- add the retrieved integers together using the accumulator register
- store the sum of them in the top of the stack.
(11) Write an assembly program to add two integers (e.g. 5 and 20) with a function called 'add'. Let the size of the stack frame be 16 bytes for 'add', and 48 bytes for 'main', and use local variables for storing the data in both functions. Set the return value of the 'main' function to the calculated sum. (e.g. 5+20=25)
(12) Write down the full content of the stack frame of the above program just before the stack frame of the 'add' function has been destroyed (i.e. two instructions before the 'ret' instruction of the 'add' function) relative to the stack pointer and the basic pointer!
(13) Write the necessary assembly instructions in AT&T syntax to perform the following operations:
- set the start label of the 'main' function
- store the basic pointer register in the stack
- move the content of the stack pointer to the basic pointer register
- create a stack frame of 48 bytes by setting the content of the stack pointer register
- store 10 in the first 4-byte long local variable in the stack frame
- store -4 in the second 4-byte long local variable in the stack frame
- move the content of the first local variable to the accumulator register
- add the content of the accumulator register to the second local variable
- set the return value of the 'main' function according to the content of the second local variable
- destroy the stack frame by setting the content of the stack pointer register
- restore the basic pointer register from the stack
- instruct the 'main' function to return to its caller
(14) Answer the following questions:
- What are the main parts of the CPU?
- What is the function of the arithmetic and logic unit?
- What are the functions of the control unit?
- How can the main parts of the computer communicate?
- What is the instruction set?
- Where are instructions and data of the currently running program stored?
- What is a stack and how can we use it?
- What kind of data are stored in the stack frame?
- What is the function of the program counter or instruction pointer (IP)?
- What is the function of the instruction register (IR)?
- What operations are performed during the fetch stage of the instruction cycle?
- What operations are performed during the execute stage of the instruction cycle?
Setting the environment of the computer
The software we need:
First download the Total Commander from the internet and install it on your computer. Then download the GCC compiler for Windows from the internet (e.g. from Sourceforge).
Create a 'temp' folder (or directory) anywhere on your computer and create a 'gcc' folder within the newly created 'temp' folder. Then copy the compressed files and folders from the zipped (probably 7-zipped) GCC archive to the 'temp\gcc' folder on your computer.
![]()
Copying the full content of the compressed 'gcc-15.2.0-gdb-16.3.90.20250511-binutils-2.45-mingw-w64-v13.0.0-ucrt.7z' file into the 'temp\gcc' folder.Create a new text file named 'setpath.bat' in the 'temp' folder, and copy the following content to it:
@echo off set x=c:\temp\gcc\bin rem set x=c:\Windows\Microsoft.NET\Framework64\v4.0.30319;%x% rem set x=c:\temp\jdk-25\bin;%x% set PATH=%x%;%PATH% echo new path: PATHNote that the default paths of the 'gcc\bin', as well as the 'Microsoft.NET\Framework64\v4.0.30319' and the 'jdk-25\bin' are underlined (because they might have to be modified according to the directory structure on your computer). In the following we assume that the 'temp' folder is located in the root directory of the 'C:' drive.
(Another way to create the 'setpath.bat' file is to download the setpath.txt file from here, rename it to 'setpath.bat', and copy the downloaded and renamed file into the 'temp' folder.)
Check the file extension of the 'setpath.bat' file (it must be '.bat'), and then open it in the Notepad. Now check, and if necessary, modify the underlined paths in the file to match the current directory structure on your computer, then save the file and close the Notepad. For example, if your 'temp' folder is located within the root folder of partition D:, you should replace 'c:\temp\' with 'd:\temp\' in the second line of the 'setpath.bat' file.
In the Total Commander window set the right panel to the 'temp' folder. Search for a single-line text field somewhere at the bottom of the Total Commander.
![]()
The command line at the bottom of the Total Commander screen. (Note that the figure shows only the minimized window of the Total Commander.)Notice that there is a caption before the command line which shows the full path of the 'temp' folder.
Open the Windows operating system's command line interpreter by typing the 'cmd' command in the command line's text field and press Enter. Now a black 'cmd' window appears displaying the c:\temp> prompt. (Note that the path before the 'temp' folder may differ on your computer.) After the prompt you can type any text-based commands.
Now type the 'setpath' command after the prompt and press Enter. Then type 'gcc --help' and you should see a help message from the GCC compiler.
![]()
The command line interface after the 'setpath.bat' and 'gcc --help' commands have been issued.