Module 2 Foundation of Computing
Module 2 Foundation of Computing
MODULE 2
Syllabus:
Binary representation of data and numbers, Integer Representation(refer classwork)
Data storage units - bits, bytes, kilobytes, etc., ASCII and Unicode
CPU Architecture and Instruction Set: Basic CPU architecture - ALU, registers, control unit
Instruction format and assembly language (basics only) Fetch- execute cycle and instruction
execution.
Bits
Bits are the basic building blocks of not only data storage, but all computers. Computers work in
binary digits, combining 0's and 1's in countless patterns. These binary digits are known as bits,
and are the smallest possible unit for data storage.
Byte
A byte consists of 8 bits
It is the standard unit of storage used to measure file sizes and memory capacity in most systems.
(All memory storage is expressed in terms of bytes)
For example, one character of text typically takes up one byte.
Bits might be the foundation upon which data storage is built, bytes are the building blocks that
truly denote the usability of any one storage solution.
Kilobyte (KB)
1 KB = 1,024 bytes (in binary systems). In decimal (SI system), 1 KB is often considered 1,000
bytes. Kilobytes are used to measure small files such as text documents.
Megabyte (MB)
1 MB = 1,024 KB = 1,048,576 bytes (binary).
In the SI decimal system, 1 MB = 1,000,000 bytes.
Megabytes are used to measure the size of larger files like images, audio files, and software
applications.
Gigabyte (GB)
1 GB 1,024 MB = 1,073,741,824 bytes (binary).
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
In the decimal = system, 1 GB = 1,000,000,000 bytes.
Gigabytes are commonly used to measure the storage capacity of devices like smartphones,
SSDs, and hard drives
2. AISCII
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
ASCII Representation of Given Characters
Using the ASCII code set given in Figure 4.3, show the internal binary representation for the
following character strings:
• a. AbC - 01000001 01100010 01000011
• b. Mike - 01001101 01101001 01101011 01100101
• c. $25.00 - 00100100 00110010 00110101 00101110 00110000 00110000
• d. (a + b) - 00101000 01100001 00100000 00101011 00100000 01100010 00101001
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
3. UNICODE
● It uses, at a minimum, a 16-bit representation for characters rather than the 8-bit format
of ASCII.
● This means that it is able to represent at least 216 = 65,536 unique characters instead of
the 28 = 256 of ASCII.
● Unicode is a superset of ASCII. The decimal values 0–127 represent exactly the same
characters in both ASCII and Unicode.
● It might seem as though 256 characters should be more than enough to represent all the
textual symbols that we would ever need—for example, 26 uppercase letters, 26
lowercase letters, 10 digits, and a few dozen special symbols, such as =+ − { } ] [\: ” ? >
< . , ; % $ # @.
● Add that all together and it still totals only about 100 symbols, far less than the 256 that
can be represented in ASCII.
● Unicode has to symbols drawn from alphabets such as Russian, Arabic, Chinese, Hebrew,
Greek, Thai, Bengali, Sanskrit, Cherokee, Inuit, and Braille, as well as mathematical
symbols, linguistic marks such as the tilde, umlaut, and accent grave, and numerous
graphical symbols.
● ASCII does not have enough room to represent them all.
● Unicode, with its 16 bits and space for over 65,000 symbols, was initially considered
large enough to accommodate this enormous range of text. However, it turned out that
even 16 bits proved insufficient to handle the exploding range of textual information
being produced around the world, and Unicode now includes a 32-bit variant in which
each separate character is represented using 32 binary digits, allowing for the possibility
of 232 distinct textual symbols, or about 4 billion!
● Currently Unicode has assigned formal mappings to more than 128,000 characters drawn
from over 135 modern and historical alphabets.
4. CPU ARCHITECTURE
● CPU architecture refers to the fundamental design of a central processing unit (CPU),
which is responsible for executing instructions and performing basic operations in a
computer system.
● CPU architecture is sometimes called Instruction Set Architecture.
● The Architecture of CPU can vary depending on the type and design
● The computer unit is made up conceptually of three major components, the
arithmetic/logic unit (ALU), the control unit (CU), and memory.
● The ALU and CU together are known as the central processing unit (CPU).
● An input/output (I/O) interface is also included in the diagram.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
4.1 The Arithmetic/Logic Unit
● The arithmetic/logic unit (ALU) is the subsystem that performs such mathematical and
logical operations as addition, subtraction, and comparison for equality.
● The ALU is made up of three parts: the registers, the interconnections between
components, and the ALU circuitry. Together these components are called the data path.
● A register is a special high-speed storage cell that holds the operands of an arithmetic
operation and that, when the operation is complete, holds its result.
● Registers are quite similar to the random access memory cell
● ALU consists of two subsections, which are:
○ Arithmetic Section: By arithmetic operations like addition, subtraction,
multiplication, and division, and all these operations and functions are performed
by ALU. Also, all the complex operations are done by making repetitive use of
the mentioned operations by ALU.
○ Logic Section: By Logical operations, we mean operations or functions like
selecting, comparing, matching, and merging the data, and all these are performed
by ALU.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
4.2 Control Unit
● These three steps are repeated over and over until we reach the last instruction in the
program, typically something called HALT, STOP, or QUIT.
● As the name suggests, a control unit controls the operations of all parts of the computer
but it does not carry out any data processing operations.
● It controls the functioning of the computer. Its main task is to maintain the flow of
information across the processor.
The control unit will also contain several 1-bit registers, sometimes known as flags, that are used
to allow the computer to keep track of special conditions such as arithmetic carry and overflow,
power failure, and internal computer error. Usually, several flags are grouped into one or more
status registers.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
● It is also known as an internal storage unit or the main memory or the primary storage or
Random Access Memory (RAM) as all these are storage devices.
● There are two types of memory in the computer, which are primary memory and
secondary memory.
4.4 Registers
● A register is a single, permanent storage location within the CPU used for a particular,
defined purpose. Registers are basic working components of the CPU.
● A register is used to hold a binary value temporarily for storage, for manipulation, and/or
for simple calculations.
● Each register is wired within the CPU to perform its specific role.
Registers also differ from memory in that they are not addressed as a memory location but
instead are manipulated directly by the control unit during the execution of instructions.
Registers may be as small as a single bit or as wide as several bytes, ranging usually from 1 to
128 bits.
Registers are used in many different ways in a computer. Depending on the particular use of a
register, a register may hold data being processed, an instruction being executed, a memory or
I/O address to be accessed, or even special binary codes used for some other purpose.
1. Accumulator
● In the CPU, the equivalent to the calculator is known as an accumulator.
● Modern CPUs provide several accumulators; these are often known as general-purpose
registers.
● Groups of similar registers are also sometimes referred to collectively as a register file.
● General-purpose registers or accumulators are usually considered to be a part of the
arithmetic/logic unit In most computers, these registers are also used to transfer data
between different memory locations, and between I/O and memory
2. The Program Counter Register - holds the address of the current instruction being executed.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
3. The Instruction Register (IR) - IR the actual instruction being executed currently by the
computer.
4. The Memory Address Register (MAR) - holds the address of a memory location.
5. The Memory Data Register (MDR), sometimes known as the memory buffer register, will
hold a data value that is being stored to or retrieved from the memory location currently
addressed by the memory address register.
The control unit will also contain several 1-bit registers, sometimes known as flags, that are used
to allow the computer to keep track of special conditions such as arithmetic carry and overflow,
power failure, and internal computer error. Usually, several flags are grouped into one or more
status registers.
5. Instruction Format
Data movement instructions move data between registers, memory, and I/O devices. They can be
used to
move bytes, words, or doublewords.
There may be a load byte instruction, a load half-word (2 bytes), a load word (4 bytes), and a
load double word (8 bytes) within the same instruction set.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
STORE : Moves data from registers to memory.
The STORE (ST) instruction is used to move data from a register to a memory location. This is
the reverse operation of the LOAD instruction, which transfers data from memory to a register.
● Arithmetic instructions are essential operations performed by the Arithmetic Logic Unit
(ALU) of a processor to handle numeric calculations. These instructions manipulate data
in registers and memory, allowing the CPU to perform mathematical computations
efficiently.
● CPU also provides instructions for integer multiplication and division.
● Many instruction sets provide integer arithmetic for several different word sizes.
● Most current CPUs also provide floating point arithmetic capabilities, although some
CPUs offer floating point arithmetic as an extension to the basic architecture.
● Some architectures also offer instructions for other, more specialized operations, such as
square root, log, and trigonometry functions.
Arithmetic Instructions(ADD,SUB)
example:
MOV AX, 5 ; Load 5 into AX
MOV BX, 3 ; Load 3 into BX
ADD AX, BX ; AX = AX + BX (AX = 5 + 3 = 8)
example:
STC ; Set carry flag (CF = 1)
ADC AL, BL
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
• SUB: Subtracts one value from another
SUB destination, source
example:
MOV AX, 10 ; Load 10 into AX
MOV BX, 4 ; Load 4 into BX
SUB AX, BX ; AX = AX - BX (AX = 10 - 4 = 6)
• SBC: Subtracts one value from another, including the carry bit
example:
STC ; Set carry flag (CF = 1)
SBB AL, BL
AND: The AND instruction is used for supporting logical expressions by performing bitwise
AND operation. The bitwise AND operation returns 1, if the matching bits from both the
operands are 1, otherwise it returns 0.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
5.4 Single Operand Instructions(INC,DEC)
These instructions operate on the value in a register, but some instruction sets provide similar
operations on memory values as well. The instruction set will contain instructions for
incrementing a value, for decrementing a value.
• NOT (Logical NOT): Performs a bitwise NOT operation on the accumulator value.
Syntax: NOT destination
MOV AL, 0b00001111 ; Load AL with binary 00001111 (decimal 15)
NOT AL ; AL = ~AL (AL = 11110000 → decimal 240)
Rotate instructions also shift the data bits left or right, but the bit that is shifted out of the end is
placed into the vacated space at the other end.
• Depending on the design of the particular instruction set, bits shifted out the end of the word
may be shifted into a different register or into the carry or overflow flag bit. The data word being
shifted might be logical or it might be numeric.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
Logical Shift Left (SHL)
● Preserves the sign bit (MSB) for signed numbers in two’s complement representation.
● Equivalent to dividing by 2, but keeps negative numbers correct.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
• Arithmetic shift instructions are commonly used to multiply or divide the original value by a
power of 2.
• Therefore, the instruction does not shift the leftmost bit, since that bit usually represents the
algebraic sign of the numeric value, obviously the sign of a number must be maintained.
• Right arithmetic shifts fill the space of moved bits with the sign bit rather than with zero.
• Rotate instructions take the bits as they exit and rotate them back into the other end of the
register.
Some instruction sets include the carry or overflow bit as part of the rotation.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
6. Instruction Word Format-Unary, Binary and Ternary
● A simple 32-bit instruction format with one address field is shown in the figure.
● In this example, the 32 bits are divided into:
Operand
● Arithmetic Instructions (such as ADD, SUB) typically require two to three operands.
● Most instructions consist of one, two, or three address fields, leading to three
categories:
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
2. Binary Instructions (Two Operands)
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
○ SUB → SUB destination, source1, source2
SUB R4, R5, R6
○ MUL → MUL destination, source1, source2
MUL R7, R8, R9
7. Assembly Language
One of the first steps toward a more user-friendly programming environment is selecting an
accessible programming language. Machine language, designed from a machine’s perspective
rather than a human’s, is complex and difficult to understand. Some specific challenges of
machine language include:
Assembly languages are called low-level programming languages, which means they are closely
related to the machine language and programs written in assembly language are called the source
program.
Languages like C++, Java, and Python, which are high-level programming languages. High-level
languages are more user oriented, they are not machine specific.
The processor does not “understand” assembly language instructions. The source program must
be translated into a corresponding machine language program, called the object program. This
translation is carried out by a piece of system software called an assembler.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
The assembler goes through the entire program, carrying out a translation of one instruction at a
time. Once the complete object program has been produced, its instructions can be loaded into
memory and executed by the processor.
Assembly languages created a more productive, user-oriented environment, and assemblers were
one of the first pieces of system software to be widely used.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
● Symbolic Addresses replace numeric memory addresses, improving readability and
maintainability.
● Comments, preceded by --, help explain code functionality.
1. Symbolic Operation Codes: Instead of binary, mnemonics like LOAD and ADD make
instructions easier to understand.
2. Symbolic Memory Addresses: Labels such as LOOPSTART allow referencing memory
locations by name rather than number.
3. Pseudo-Operations: These provide useful features like data generation and code
structuring.
Using symbolic labels instead of numeric addresses improves program clarity and
maintainability. For example:
LOOPSTART: LOAD X
JUMP LOOPSTART
Here, LOOPSTART represents the memory address of LOAD X. If instructions shift due to
modifications, the assembler automatically updates references, eliminating manual address
adjustments.
JUMP LOOP
... ← Point A
LOOP: LOAD X
New instruction is added to the program at point A. When the modified program is translated by
the assembler into machine language, all instructions following point A are placed in a memory
cell whose address is 1 higher than it was before .
The JUMP refers to the LOAD instruction only by the name LOOP, not by the address where it
is stored. Neither the JUMP nor the LOAD instruction needs to be changed.
.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
Example (After Modification - Added Instruction at Point A):
Assembly language provides pseudo-op codes to help generate data in the correct binary format.
FIVE: .DATA +5
The assembler:
LOAD FIVE
This is equivalent to LOAD 53 (if FIVE is stored at memory location 53). Using labels prevents
accidental errors, such as mistakenly loading data from memory address 5 instead of FIVE.
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
The Instruction Set & CPU Role
The instruction set is a predefined collection of tasks that the CPU is designed to execute. It
retrieves and processes instructions from the main memory to carry out operations efficiently.
1. Fetch Phase
The fetch phase involves retrieving the instruction from memory. Since the address of the current
instruction is stored in the program counter (PC), the first step is to transfer this address to the
memory address register (MAR):
(step 1) PC → MAR
This allows the computer to retrieve the instruction stored at that address. The instruction is then
moved from the memory data register (MDR) to the instruction register (IR):
(step 2) MDR → IR
At this point, the instruction register holds the instruction for the remainder of the cycle.
2. Decode Phase
During the decode phase, the CPU interprets the instruction in the instruction register to
determine the necessary operations. It extracts the address portion of the instruction and prepares
for execution:
This step allows the CPU to access the required data from memory.
3. Execute Phase
The CPU performs the operation specified by the instruction. For a load instruction, data from
memory is transferred to the accumulator:
(step 4) MDR → A
After execution, the program counter is incremented to move to the next instruction:
(step 5) PC + 1 → PC
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
Examples of Instructions
Load Instruction
PC → MAR
MDR → IR
IR[address] → MAR
MDR → A
PC + 1 → PC
Store Instruction
PC → MAR
MDR → IR
IR[address] → MAR
A → MDR
PC + 1 → PC
Add Instruction
PC → MAR
MDR → IR
IR[address] → MAR
A + MDR → A
PC + 1 → PC
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025
---
Author: Athithya S.
Assistant Professor(CSE), Christ College of Engineering
Date: 26 March 2025