Fundamentals of a computer system

  • What is a computer? What are the components of a computer system?

Introduction

A computer is an electronic device that accepts inputs from the input devices, processes them and displays the result in output devices. The result obtained can also be saved on the storage devices for future use.

A computer is composed of two components: Hardware and Software.

Hardware: The physical parts of a computer system are called hardware. For example, input devices(Keyboard, Mouse, etc.), memory devices(RAM, ROM, Hard disk, etc.), output devices(Monitor, Speaker, etc. ), processors, etc.

  • Input devices: These devices read input from the user. For example, Keyboard, Mouse, Touchpad, etc.

  • Output devices: These devices provide an output to the user. For example, Monitor, Printer, Speaker, etc.

  • CPU: Performs different operations based on instructions.

  • Storage/Memory Devices: Stores the data or output.

Hierarchy Of Memory

  1. Internal Memory: Memory integrated within the CPU or closest to the CPU.

    1. Register: A, W, Z, B, C, D, E, H, L 8085up

    2. Cache: L1 Cache, L2 Cache

  2. Primary/Main Memory: Memory that communicates with the CPU.

    1. RAM: volatile memory. Read and Write Operations

    2. ROM: non-volatile memory. Read Only Operation

  3. Secondary Memory: stores the data permanently.

    1. Hard disk: stores the data permanently in a disk.

    2. USB Drive / Pendrive: stores the data permanently and is easily portable from one device to another.

Major Factors Of Memory

Factors

Memory

Speed

Internal Memory  >  Primary Memory  > Secondary Memory

Size

Internal Memory  <  Primary Memory  < Secondary Memory

Cost

Internal Memory  >  Primary Memory  > Secondary Memory

Software: Software is a set of programs that performs a specific task. For example, OS, media player, file manager, etc.
There are two types of software: System Software and Application Software

System Software: A software that is used to communicate with hardware and/or application software is called system software.

  1. Operating System (OS) - Windows, Linux, etc.

  2. Utility Software - Antivirus, Disk Management Tools, etc.

  3. Device Drivers - Audio Drivers, Video Drivers, etc.

Application Software: A software that is used to perform a specific application or a set of operations is called an application software.
An application software is further categorized into two types: Tailored Software and Packaged Software

  1. Tailored/Customized/Bespoke Software: An application software that is developed as per the requirements of a particular user or business entity is called a tailored software application. For example, School Attendance System, Library Management System, etc.

  2. Packaged/Generic Software: An application software that is developed as an off-the-shelf product designed for many consumers and can meet many client’s general requirements is called a packaged software application. For example, MS Office.

Features of good software

  1. Portability: the ability of a program to run on different platforms with or without minimal changes.

  2. Maintainability: should be easy to bring changes or fix bugs.

  3. Reliable: should be reliable or trustworthy i.e. should always work.

  4. Efficient: should be efficient in performing the task/job.

  5. Readability: should be understandable by other programmers/developers.

Working on a computer

  • How does a computer operate?

When you press the power button to start a computer system, the boot loader program stored in ROM locates the operating system in the hard disk and loads it to the RAM. The OS loaded in the RAM is executed by the CPU with the help of a cache and register for faster execution. This is how a computer starts. The main takeaway of this section is how different memories interact with each other. In summary, we store/install our program or software in secondary memory and when we open the installed software, it is loaded to the RAM from secondary memory and executed by the CPU.

We will be writing programs/applications in the C programming language which will also be stored in secondary memory. When we open/run that program, it will be loaded to RAM and executed by the CPU.

Instruction vs. Program vs. Software

  • Understand Instruction, Program and Software

Instruction: a single machine level operation.

Program: a set of instructions that perform a specific task.

Software: a set of programs that perform a specific task.


Program: A set of instructions that performs a specific task is called a program. For example, a program to perform mathematical calculations.

Instruction: An instruction refers to a single machine-level operation that can be executed by the processor. These instructions are typically represented in binary codes or mnemonics that correspond to specific hardware operations, such as arithmetic operations or memory manipulations.

  1. Assembly Instruction: an instruction written in assembly language using mnemonics. For example, ADD A, B is an 8085 microprocessor instruction to add the contents of register B to the contents of register A (i.e. accumulator) and store the result in the accumulator.

  2. Binary Instruction: an instruction written in machine language using only 0 or 1. For example, the equivalent binary instruction of the above assembly instruction will be

Opcode

Source Register

Source Register

Destination Register

Function Code

10000000

111

000

111

000

ADD A, B

A

B

A

ADD

Hence, 10000000111000111000 is a binary instruction to perform an addition.


Representation of data in binary

  • How does a computer represent different types of data (integer, floating, character, string, etc.)?

Binary Representation of a character/string:

A single character or a string is generally represented in binary using the ASCII (American Standard Code for Information Interchange) code. They can also be represented using other encoding techniques such as Unicode.

We don't need to remember every ASCII value but the following values are some of the frequently used values.

Character

ASCII Value

\0 (NULL)

0

A - Z

65 - 90

a - z

97 - 122

The ASCII value of the string Hello will be :
H = 1001000, e = 1100101, l = 1101100, l = 1101100, o = 1101111.

i.e. 10010001100101110110011011001101111

Note: The difference in the ASCII values of uppercase and lowercase letters is 32. i.e. A = 65 and a = 65+32 = 97
Z = 90 and z = 90+32 = 122

Binary Representation of an integer number:

An integer number is converted into a binary number. The MSB of the binary number is used to distinguish between a positive and a negative number. If the MSB is 0 then, the number is a positive number else, it is a negative number.

(123)10 in decimal = (0 1111011)2 in binary

(-123)10 in decimal = (1 1111011)2 in binary

Binary Representation of a Floating Point Number:

A floating point number is generally represented in binary using the IEEE standard. For example, IEEE 754 standard representation of 123.45 is obtained as follows:

  1. Convert 123.45 to binary:

    • Integer part: 123 in decimal is 1111011 in binary.

    • Fractional part: Convert 0.45 to binary (approximately). 0.0111001100110011...

  2. Normalize the binary representation:

    • Combine the integer and fractional parts: 1111011.0111001100110011...
  3. Determine the exponent:

    • The exponent is 6 (from the normalized form).

    • Add the bias (127) to the exponent: 6 + 127 = 133

    • Convert the exponent to binary: 133 in decimal is 10000101 in binary.

  4. Encode the sign, exponent, and fraction:

    • Sign bit: 0 (positive)

    • Exponent: 10000101 (from step 3)

    • Fraction: Take the fractional part from the normalized form and pad with zeros to fill 23 bits: 01110011001100110011010

Putting it all together, the IEEE 754 representation becomes:

0 10000101 01110011001100110011010

Programming Languages

A programming language is a formal system of rules and syntax that enables humans to communicate instructions to computers. It serves as an intermediary between human-readable code and machine-executable instructions. Programming languages provide a way to write algorithms, create software, and control hardware by specifying a set of commands, functions, and structures.

Classification of Programming Language

Low-Level Language:

A set of instructions written for a computer system either at the machine level (0 or 1) or the assembly level (mnemonics) with the proper knowledge of the hardware involved is called a low-level program. Such programming languages are commonly referred to as low-level programming languages.

Machine Level Language:

A set of instructions written for a computer system at the machine level (0 or 1) with the proper knowledge of the hardware involved is called a machine-level program. Such programming languages are commonly referred to as machine-level programming languages. This is the only language that a computer is capable of understanding without any translation. The term machine code and object code are used interchangeably.

Assembly Level Language:

A set of instructions written for a computer system at the assembly level (mnemonics) with the proper knowledge of the hardware involved is called an assembly-level program. Such programming languages are commonly referred to as assembly-level programming languages. Since the instructions are written using mnemonic codes, they need to be translated into machine code before execution.

High-Level Language:

A set of instructions written for a computer system in a human-friendly language without the depth of knowledge of hardware involved is called a high-level program. Such programming languages are commonly referred to as high-level programming languages. Since the instructions are written in human-friendly language / high level, they need to be translated into machine code before execution. C, C++, Python, Java, etc. are some popular high-level languages.

Language Translator

A language translator is a tool or a program that converts/translates the source code written in one programming language into an equivalent code of another programming language. These language translators convert our high-level codes into machine-understandable codes. The popular language translators are Assemblers, Compilers and Interpreters.

Assembler

The language translator that translates the code written in assembly language into object code is called an assembler.

Compiler

The language translator that translates the code written in a high-level language into assembly code and eventually an object code through assembler is called a compiler. The compiler translates/compiles the whole source code at once and gives an object code that could be loaded into memory during execution. Since the whole file is translated all at once before execution, compiler-based languages are fast. C and C++ use compilers to translate source code into object code.

Interpreter

The language translator that translates the code written in a high-level language into object code is called an interpreter. The interpreter translates/interprets the source code line by line and gives an object code that could be loaded into memory during execution. Since the translation is performed multiple times due to the line-by-line translation approach, interpreter-based languages are slower than compiler-based languages. Python uses an interpreter to translate source code into object code.

Generation of Programming Language

It's important to note that the division of languages into generations is not universally agreed upon, and the boundaries between generations can be subjective. The categorization provided below is a commonly accepted representation of the evolution of programming languages.

First Generation Language (1GL)

Machine Language:

First-generation languages are machine languages that directly correspond to the hardware architecture of a computer. Instructions are written using binary code, consisting of sequences of 0s and 1s. Each instruction represents a specific operation or command that the computer can execute. Machine language is low-level and specific to a particular computer architecture, making it challenging to program and understand.

Second Generation Language (2GL)
Assembly Language:

Assembly languages provide a more human-readable representation of machine code by using symbols and mnemonics instead of binary code. These languages are specific to a particular computer architecture and require an assembler to translate the code into machine language.

Third Generation Language (3GL)

High-Level Language:

Third-generation languages are high-level programming languages designed to be more readable and independent of the underlying hardware architecture. They provide higher-level abstractions and a more English-like syntax, making it easier for programmers to write code. Programs written in high-level languages need to be compiled or interpreted into machine code before execution. C, Java, Python, etc. are some of the examples of 3GL.

Fourth Generation Language (4GL)

Domain Specific Language:

Fourth-generation languages are domain-specific languages (DSLs) designed for specific applications or domains. They provide a higher level of abstraction than general-purpose languages and are often used for database management, report generation, or graphical user interface development. 4GLs focus on simplifying the development process by providing built-in functionalities and tools specific to the target domain. SQL (Structured Query Language), MATLAB (Matrix Laboratory), R (Statistical Programming Language), etc. are some of the examples of 4GL.

Fifth Generation Language (5GL)

Natural Language:

Fifth-generation languages are programming languages focused on artificial intelligence (AI) and symbolic computation. They aim to facilitate the development of AI systems and support advanced concepts such as natural language processing, expert systems, and machine learning. 5GLs often provide high-level abstractions and declarative syntax for expressing complex algorithms and problem-solving methodologies. Prolog, LISP(LISt Processing), Haskell, etc. are some of the examples of 5GL.

Did you find this article valuable?

Support Engineering Insights by becoming a sponsor. Any amount is appreciated!