Ift212 Lecture Notes
Ift212 Lecture Notes
LECTURE NOTE
First generation
The period of first generation was 1946-1959. The computers of first generation used
vacuum tubes as the basic components for memory and circuitry for CPU (Central
Processing Unit). These tubes, like electric bulbs, produced a lot of heat and were
prone to frequent fusing of the installations, therefore, were very expensive and
could be afforded only by very large organizations. In this generation, mainly batch
processing operating system were used. Punched cards, paper tape, and magnetic
tape were used as input and output devices. The computers in this generation used
machine code as programming language.
Second generation
The period of second generation was 1959-1965. In this generation transistors
were used that were cheaper, consumed less power, more compact in size, more
reliable and faster than the first generation machines made of vacuum tubes. In
this generation, magnetic cores were used as primary memory and magnetic tape
and magnetic disks as secondary storage devices. In this generation assembly
language and high-level programming languages like FORTRAN, COBOL
were used. The computers used batch processing and multiprogramming
operating system.
Fourth generation
The period of fourth generation was 1971-1980. The computers of fourth generation
used Very Large Scale Integrated (VLSI) circuits. VLSI circuits having about 5000
transistors and other circuit elements and their associated circuits on a single chip
made it possible to have microcomputers of fourth generation. Fourth generation
computers became more powerful, compact, reliable, and affordable. As a result, it
gave rise to personal computer (PC) revolution. In this generation time sharing, real
time, networks, distributed operating system were used. All the high-level languages
like C, C++, DBASE etc., were used in this generation.
Fifth generation
The period of fifth generation is 1980-till date. In the fifth generation, the VLSI
technology became ULSI (Ultra Large Scale Integration) technology, resulting in
the production of microprocessor chips having ten million electronic components.
This generation is based on parallel processing hardware and AI (Artificial
Intelligence) software. AI is an emerging branch in computer science, which
interprets means and method of making computers think like human beings. All the
high-level languages like C and C++, Java, .Net etc., are used in this generation.
AI includes:
Robotics
Neural Networks
Game Playing
Development of expert systems to make decisions in real life situations.
Natural language understanding and generation.
1. Registers: These are temporary storage locations within the CPU used to hold
data and instructions during execution.
a. Program Counter (PC): This holds the address of the next instruction to
be fetched from Memory.
b. Instruction Register (IR): This holds the instructions that are currently
being executed
c. Instruction Decoder: It decodes and interprets the contents of the IR,
and splits a whole instruction into fields for the Control Unit to
interpret.
2. Control Unit: It co-ordinates all activities within the CPU, has connections to
all parts of the CPU, and includes a sophisticated timing circuit.
3. Arithmetic and Logic Unit (ALU): It carries out arithmetic and logical
operations.
Arithmetic operations like addition, subtraction, multiplication,
division and
Logical operations like AND, OR, NOT operations.
Within ALU, input registers hold the input operands and output register holds
the result of an ALU operation. Once completing ALU operation, the result is
copied from the ALU output register to its final destination.
4. Buses: The internal bus of a CPU includes three buses, which are the Address
bus, the data bus and the control bus.
a. Data Bus:
Data bus is the most common type of bus. It is used to transfer data
between different components of computer. The number of lines in data
bus affects the speed of data transfer between different components.
The data bus consists of 8, 16, 32, or 64 lines. A 64-line data bus can
transfer 64 bits of data at one time. The data bus lines are bi-directional.
It means that CPU can read data from memory using these lines CPU
can write data to memory locations using these lines.
b. Address Bus:
Many components are connected to one another through buses. Each
component is assigned a unique ID. This ID is called the address of
that component. If a component wants to communicate with another
component, it uses address bus to specify the address of that
component. The address bus is a unidirectional bus. It can carry
information only in one direction. It carries address of memory
location from microprocessor to the main memory.
c. Control Bus:
Control bus is used to transmit different commands or control signals
from one component to another component. Suppose CPU wants to
read data from main memory, it will use the control bus. It is also used
to transmit control signals like ASKS (Acknowledgement signals). A
control signal contains the following:
Timing information: It specifies the time for which a device can
use data and address bus.
Command Signal: It specifies the type of operation to be
performed. Suppose that CPU gives a command to the main
memory to write data, the memory sends acknowledgement
signal to CPU after writing the data successfully. CPU receives
the signal and then moves to perform some other action.
5. Memory (will be discussed later)
3. Stack Organization
This organization uses a stack, a data structure where the last element added is the
first element retrieved (LIFO). The stack is primarily used for managing data during
subroutine calls, local variables, and expression evaluation. It can be efficient for
certain types of operations and simplifies some programming tasks.
1.3 MEMORY
Memory unit enables us to store data inside the computer. The memory can be
referred to as the storage area in which running programs are kept, and it also
contains data needed by the running programs. It enables a processor to access
running applications and services that are temporarily stored in a specific memory
location.
The memory is divided into large number of small parts called cells. Each location
or cell has a unique address, which varies from zero to memory size minus one. For
example, if the computer has 64k words, then this memory unit has 64 * 1024 =
65536 memory locations. The address of these locations varies from 0 to 65535. The
memory unit can be categorized into three namely, cache, primary memory and
secondary memory.
1.3.1 Primary Memory
Primary storage is a volatile memory that holds only those data and instructions on
which the computer is currently working on. It contains a large number of
semiconductor storage cells, capable of storing a bit of information. The data and
instruction required to be processed resides in the main memory. Primary memory
is divided into two: Random Access Memory (RAM) and Read Only Memory
(ROM).
Characteristics
It has a limited capacity
It is generally made up of semiconductor devices
It is a volatile form of memory, means when the computer is shut down,
anything contained in RAM is lost.
These memories are not as fast as the cache.
The very first ROMs were hard-wired devices that contained a pre-programmed set
of data or instructions. This kind of ROMs are known as masked ROMs, which are
inexpensive.
PROM is read-only memory that can be modified only once by a user. The user buys
a blank PROM and enters the desired contents using a PROM program. Inside the
PROM chip, there are small fuses which are burnt open during programming. It can
be programmed only once and is not erasable.
Terminologies in Cache
Split cache: It has separate data cache and a separate instruction cache. The two
caches work in parallel, one transferring data and the other transferring instructions.
A dual or unified cache: The data and the instructions are stored in the same cache.
A combined cache with a total size equal to the sum of the two split caches will
usually have a better hit rate.
Mapping Function: A mapping function specifies the correspondence between the
main memory blocks and those in the cache.
Cache Replacement: When the cache is full and a memory word that is not in the
cache is referenced, the cache control hardware must decide which block should be
removed to
create space for the new block that contains the referenced word. The collection of
rules for making this decision is the replacement algorithm.
Cache performance
When the processor needs to read or write a location in main memory, it first checks
for a corresponding entry in the cache. If the processor finds that the memory
location is in the cache, a cache hit is said to have occurred. If the processor does
not find the memory location in the cache, a cache miss has occurred.
When a cache miss occurs, the cache replacement is made by allocating a new entry
and copies in data from main memory. The performance of cache memory is
frequently measured in terms of a quantity called Hit ratio.
Cache performance can be enhanced by
CPU execution time of a given task is defined as the time spent by the system
executing that task, including the time spent executing run-time or system
services.
Therefore, to curb this challenges, memory unit must be divided into smaller
memories for more storage, speedy program executions and the enhancement of the
processor performance. The recently accessed files or programs must be placed in
the fastest memory since the memory with large capacity is cheap and slow and the
memory with smaller capacity is fast and costly. The organization of smaller
memories to hold the recently accessed files or programs closer to the CPU is termed
memory hierarchy. These memories are successively larger as they move away from
the CPU. The hierarchy system encompasses all the storage devices used in a
computer system. It ranges from the cache memory, which is smaller in size but
faster in speed to a relatively auxiliary memory which is larger in size but slower in
speed. The smaller the size of the memory the costlier it becomes.
The Memory Hierarchy Design is classified into 2 major types:
1. Internal Memory
It is also known as Primary memory. It is directly accessible by the processor. It
includes three basic levels, as given below
Zero level (CPU Registers)
level 1 (Cache Memory)
Level 2 (Main memory)
2. External Memory
It is also known as Secondary memory. It is accessible by the processor via the I/O
Module. It includes level 3 (Magnetic Disk), level 4(Optical Disk and Magnetic
Tape). Let explain the memory hierarchy with a block diagram as shown below,
Level 0 − Registers
The registers are present inside the CPU and because they are present inside the
CPU, they have least access time. Registers are most expensive and smallest in size
generally in kilobytes. They are used to store data/instruction in execution and are
implemented by using Flip-Flops.
Level 1 – Cache
Cache memory is used to store the segments of a program that are frequently
accessed by the processor. It is expensive and the smallest in size, generally in
Megabytes and is implemented by using Static RAM. It is very costly compared to
the main memory and the auxiliary memory.
Hit: If the requested data is found in the upper levels of memory hierarchy it is called
hit.
Miss: If the requested data is not found in the upper levels of memory hierarchy it
is called miss.
Hit rate or Hit ratio: It is the fraction of memory access found in the upper level.
It is a performance metric. Hit Ratio = Hit/ (Hit + Miss)
Miss rate: It is the fraction of memory access not found in the upper level (1-hit
rate).
Hit Time: The time required for accessing a level of memory hierarchy, including
the time needed for finding whether the memory access is a hit or miss.
Miss penalty: The time required for fetching a block into a level of the memory
hierarchy from the lower level; this includes the time to access, transmit, insert it to
new level and pass the block to the requestor.
There are many methods or techniques which can be used to convert numbers from
one base to another. These include −
Decimal to Other Base System
Other Base System to Decimal
Other Base System to Non-Decimal
Shortcut method − Binary to Octal
Shortcut method − Octal to Binary
Shortcut method − Binary to Hexadecimal
Shortcut method − Hexadecimal to Binary
a. Sign-Magnitude
The Most Significant Bit (MSB) of signed binary numbers is used to indicate the sign of the
numbers. Hence, it is also called a sign bit. In sign-magnitude, the MSB is used for representing
sign of the number and the remaining bits represent the magnitude of the number. The positive
sign is represented by placing ‘0’ in the sign bit. Similarly, the negative sign is represented by
placing ‘1’ in the sign bit.
If the signed binary number contains ‘N’ bits, then N−1 bits only represent the magnitude of the
number since one bit, MSB is reserved for representing sign of the number. Below is an 8-bit
representation:
magnitude
Sign bit
Example
Consider the negative decimal number -108. The magnitude of this number is 108. We know the
unsigned binary representation of 108 is 1101100. It is having 7 bits. All these bits represent the
magnitude.
Since the given number is negative, consider the sign bit as 1, which is placed on left most side of
magnitude.
−108
−10810 = 11101100
Therefore, the sign-magnitude representation of -108 is 11101100.
Signed sign-
decimal magnitude
+6 0110
-6 1110
+0 0000
-0 1000
+7 0111
-7 1111
The above are examples of sign magnitude. Note that it is 4-bit representation
Complement Arithmetic
Complements are used in the digital computers in order to simplify the subtraction
operation and for the logical manipulations.
Binary system complements
As the binary system has base r = 2. So the two types of complements for the binary
system are 2's complement and 1's complement.
b. 1's complement
The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's.
This is called as taking complement or 1's complement. Example of 1's Complement
is as follows.
c. 2's complement
The 2's complement of binary number is obtained by adding 1 to the Least
Significant Bit (LSB) of 1's complement of the number.
2's complement = 1's complement + 1
Example of 2's Complement is as follows.
2.3 Binary Arithmetic
Binary arithmetic is essential part of all the digital computers and many other digital
system.
Binary Addition
It is a key for binary subtraction, multiplication, division. There are four rules of
binary addition.
Example – Subtraction
Binary Multiplication
Example − Multiplication
Binary Division
Binary division is similar to decimal division. It is called as the long division
procedure.
Example − Division
Evaluate:
i. 110101 – 100101
Solution:
a. 1’s complement of 100101 is 011010,
b. add this to the minuend. You obtain 001111 with a carry.
c. Add 1 to get the final answer
d. Answer is 010000
3.0 ASSEMBLY
ASSEMBLY REGISTERS
Processor operations mostly involve processing data. This data can be stored in
memory and accessed from there. However, reading data from and storing data into
memory slows down the processor, as it involves complicated processes of sending
the data request across the control bus and into the memory storage unit and getting
the data through the same channel. To speed up the processor operations, the
processor includes some internal memory storage locations, called REGISTERS.
The registers store data elements for processing without having to access the
memory. A limited number of registers are built into the processor chip.
Processor Registers
There are ten 32-bit and six 16-bit processor registers in IA-32 architecture. The IA-
32, also known as x86 or i386, is a 32-bit instruction set architecture designed by
Intel. The registers are grouped into three categories:
1. General registers
2. Control registers, and
3. Segment registers
1. The general registers are further divided into the following groups -
a. Data registers
b. Pointer registers
c. Index registers
a. Data Registers
Four 32-bit data registers are used for arithmetic, logical, and other operations.
These 32-bit registers can be used in three ways-
As complete 32-bit data registers: EAX, EBX, ECX, EDX.
Lower halves of the 32-bit registers can be used as four 16-bit data
registers: AX, BX, CX, and DX.
Lower and higher halves of the above-mentioned four 16-bit registers can
be used as eight 8-bit data registers: AH, AL, BH, BL, CH, CL, DH, and
DL.
Some of these data registers have specific use in arithmetic operations
AX is the primary accumulator; it is used in input/output and most arithmetic
instructions. For example, in multiplication operation, one operand is stored in EAX
or AX or AL register according to the size of the operand.
BX is known as the base register; used in indexed addressing.
CX is known as the count register, as the ECX, CX registers store the loop count in
iterative operations.
DX is known as the data register. It is also used in input/output operations. It is also
used with AX register along with DX for multiply and divide operations involving
large values.
b. Pointer Registers
These are 32-bit EIP, ESP, and EBP registers and corresponding 16-bit right portions
IP, SP, and BP. There are three categories of pointer registers:
Instruction pointer (IP)
Stack pointer (SP)
Base pointer (BP)
IP - The 16-bit IP register stores the offset address of the next instruction to be
executed. IP in association with the CS register (as CS:IP) gives the complete
address of the current instruction in the code segment.
SP - The 16-bit SP register provides the offset value within the program stack. SP in
association with the SS register (SS:SP) refers to be current position of data or
address within the program stack.
BP - The 16-bit BP register mainly helps in referencing the parameter variables
passed to a subroutine. The address in SS register is combined with the offset in BP
to get the location of the parameter. BP can also be combined with DI and SI as base
register for special addressing.
c. Index registers
The 32-bit index registers, ESI and EDI, and their 16-bit rightmost portions. SI and
DI, are used for indexed addressing and sometimes used in addition and subtraction.
There are two sets of index pointers -
Source Index - It is used as source index for string operations.
Destination Index - It is used as destination index for string operations.
2. Control Registers
The 32-bit instruction pointer register and the 32-bit flags register combined are
considered as the control registers.
Many instructions involve comparisons and mathematical calculations which may
cause change of status of the flags. Some other conditional instructions may test the
value of these status flags to take the control flow to other locations.
The common flag bits are:
Overflow flag (OF) - It indicates the overflow of a high-order bit (leftmost bit) of
data after a signed arithmetic operation.
Direction flag (DF) - It determines left or right direction for moving or comparing
string data. When the DF value is 0, the string operation takes left-to-right direction
and when the value is set to 1, the string operation takes right-to-left direction.
Interrupt flag (IF) - It determines whether the external interrupts like keyboard entry,
etc., are to be ignored or processed. It disables the external interrupt when the value
is 0 and enables interrupts when set to 1.
Trap flag (TF) - It allows setting the operation of the processor in single-step mode.
The DEBUG program we used sets the trap flag, so we could step through the
execution one instruction at a time.
Sign flag - It shows the sign of the result of an arithmetic operation. This flag is set
according to the sign of a data item following the arithmetic operation. The sign is
indicated by the high-order of leftmost bit. A positive result clears the value of SF
to 0 and negative result sets it to 1.
Zero flag (ZF) - It indicates the result of an arithmetic or comparison operation. A
nonzero result clears the zero flag to 0, and a zero result sets to 1.
Auxiliary Carry Flag (AF) - It contains the carry from bit 3 to bit 4 following an
arithmetic operation; used for specialized arithmetic. The AF is set when a 1-byte
arithmetic operation causes a carry from bit 3 into bit 4.
Parity Flag (PF) - It indicates the total number of 1-bits in the result obtained from
an arithmetic operation. An even number of 1-bits clears the parity flag to 0 and an
odd number of 1-bits sets the parity flag to 1.
Carry Flag (CF) - It contains the carry of 0 or 1 from a high-order bit (leftmost) after
an arithmetic operation. It also stores the contents of last bit of
a shift or rotate operation.
3. Segment Registers
Segments are specific areas defined in a program for containing data, code and stack.
There are three main segments:
Code segment (CS): It contains all the instructions to be executed. A 16-bit CS
register stores the starting address of the code segment.
Data segment (DS): It contains data, constants and work areas. A 16-bit DS register
stores the starting address of the data segment.
Stack segment (SS): It contains data and return addresses of procedures or
subroutines. It is implemented as a 'stack' data structure. The SS register stores the
starting address of the stack.
The segment registers stores the starting addresses of a segment. To get the exact
location of data or instruction within a segment, an offset value (or displacement) is
required. To reference any memory location in a segment, the processor combines
the segment address in the segment register with the offset value of the location.
Expression: X = (A+B)*(C+D)
Postfixed: X=AB+CD+*
TOP means top of stack
M[X] is any memory location
PUSH A TOP = A
PUSH B TOP = B
PUSH C TOP = C
PUSH D TOP = D
Expression: X = (A+B)*(C+D)
AC is accumulator
M[] is any memory location
M[T] is temporary location
LOAD A AC = M[A]
ADD B AC = AC + M[B]
STORE T M[T] = AC
LOAD C AC = M[C]
ADD D AC = AC + M[D]
MUL T AC = AC * M[T]
STORE X M[X] = AC
MUL R1, R2 R1 = R1 * R2
MOV X, R1 M[X] = R1
Expression: X = (A+B)*(C+D)
R1, R2 are registers
M[] is any memory location
Advantages
Zero-address instructions
They are simple and can be executed quickly since they do not require any
operand fetching or addressing. They also take up less memory space.
One-address instructions
They allow for a wide range of addressing modes, making them more flexible
than zero-address instructions. They also require less memory space than two
or three-address instructions.
Two-address instructions
They allow for more complex operations and can be more efficient than one-
address instructions since they allow for two operands to be processed in a
single instruction. They also allow for a wide range of addressing modes.
Three-address instructions
They allow for even more complex operations and can be more efficient than
two-address instructions since they allow for three operands to be processed in
a single instruction. They also allow for a wide range of addressing modes.
Disadvantages
Zero-address instructions
They can be limited in their functionality and do not allow for much flexibility
in terms of addressing modes or operand types.
One-address instructions
They can be slower to execute since they require operand fetching and
addressing.
Two-address instructions
They require more memory space than one-address instructions and can be
slower to execute since they require operand fetching and addressing.
Three-address instructions
They require even more memory space than two-address instructions and can
be slower to execute since they require operand fetching and addressing.
2. Direct Addressing:
Definition: The instruction contains the actual memory address of the
operand.
Example: MOV R1, [1000] (Move the contents of memory location 1000
into register R1).
Use: Used for accessing data directly from memory when the address is
known.
3. Indirect Addressing:
Definition: The instruction contains a memory address that holds the
actual address of the operand.
Example: MOV R1, [1000] (Memory location 1000 contains the address
of the operand).
Use: Used for accessing data that's located within a table of addresses,
often to avoid hardcoding addresses.
4. Register Addressing:
Definition: The instruction specifies a register as the operand.
Example: MOV R1, R2 (Move the contents of register R2 into register
R1).
Use: Used for fast data transfer within the CPU's registers.
6. Indexed Addressing:
Definition: The effective address of the operand is calculated by adding
the contents of a register (index register) to a constant (index offset).
Example: MOV R1, [BASE+INDEX] (Move the contents of memory
location calculated by adding the contents of BASE register to the
INDEX offset).
Use: Used for accessing array elements, where the index register is used
to calculate the memory offset.
7. Relative Addressing:
Definition: The effective address is calculated by adding the contents
of the program counter (PC) to a displacement value in the instruction.
Example: JMP +10 (Jump to the instruction 10 bytes forward from the
current PC location).
Use: Used for jumping to instructions within a limited range relative to
the current instruction's location.
8. Stack Addressing:
Definition: Operands are accessed from a stack, which is a last-in, first-
out (LIFO) data structure.
Example: PUSH R1 (Push the contents of register R1 onto the stack).
Use: Used for function calls, subroutine calls, and managing data during
program execution.
9. Auto-Increment/Decrement Addressing:
Definition: The register containing the address of the operand is
incremented or decremented before or after the operand is accessed.
Example: MOV R1, [R2+] (Move the contents of the memory location
pointed to by register R2 into R1, then increment R2).
Use: Used for accessing sequential elements in an array or table, often
used with data structures like stacks.