0% found this document useful (0 votes)
13 views23 pages

Foc m2 Notes

The document discusses the foundations of computing, focusing on number systems, data representations, and how computers use binary for operations. It explains the conversion between decimal and binary, the representation of various data types (numbers, text, images, sound), and the significance of data storage units. Additionally, it covers integer representation methods and character encoding standards like ASCII and Unicode.

Uploaded by

jeromegeorge1903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

Foc m2 Notes

The document discusses the foundations of computing, focusing on number systems, data representations, and how computers use binary for operations. It explains the conversion between decimal and binary, the representation of various data types (numbers, text, images, sound), and the significance of data storage units. Additionally, it covers integer representation methods and character encoding standards like ASCII and Unicode.

Uploaded by

jeromegeorge1903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Foundations Of Computing: From Hardware Essentials To Web Design

GXEST203 2024 scheme


MODULE-2
As humans, we generally count and perform arithmetic using the decimal, or base 10, number system. The base of a
number system is simply the number of different digits, including zero, that exist in the number system. Historically,
it seems that the main reason that we use base 10 is that humans have ten fingers, which is as good a reason as any.
Any number can be represented equivalently in any base, and it is always possible to convert a number from one base
to another without changing its meaning.
Computers perform all of their operations using the binary, or base 2, number system. All program code and data are
stored and manipulated in binary form.Calculations are performed using binary arithmetic. Each digit in a binary
number is known as a bit (for binary digit) and can have only one of two values, 0 or 1. Bits are commonly stored and
manipulated in groups of 8 (known as a byte), 16 (usually known as a halfword), 32 (a word), or 64 bits (a
doubleword). Sometimes other groupings are used.
The knowledge of the size limits for calculations in a particular language is sometimes extremely important, since
some calculations can cause a numerical result that falls outside the range provided for the number of bits used. In
some cases this will produce erroneous results, without warning to the end user of the program.It is useful to
understand how the binary number system is used within the computer. Often, it is necessary to read numbers in the
computer in their binary or equivalent hexadecimal form.

1. Data Representations
1. Numbers
Numbers are typically represented in binary format by converting each digit to binary equivalents.
 Example: Representing the decimal number 5 in binary.
o 5 in decimal is 101 in binary.
 Example: Representing 10 in binary.
o 10 in decimal is 1010 in binary.
2. Text (Characters)
Text characters are represented using standardized encoding schemes, like ASCII (American Standard Code for
Information Interchange) or Unicode.
 Example: Representing the character 'A' in ASCII.
o In ASCII, 'A' is represented by the decimal number 65.
o 65 in binary is 01000001.
 Example: Representing the character 'a'.
o In ASCII, 'a' is represented by 97.
o 97 in binary is 01100001.
3. Images
Images are represented in binary by breaking down each pixel into binary values that represent color information. In
grayscale images, each pixel might be represented by an 8-bit binary number, while in color images (like RGB), each
color channel (Red, Green, Blue) may use 8 bits, giving a total of 24 bits per pixel.
 Example: A grayscale pixel with an intensity value of 200.
o 200 in binary is 11001000.
 Example: An RGB pixel with values (Red=255, Green=0, Blue=127).
o Red: 11111111, Green: 00000000, Blue: 01111111.
4. Sound
Sound is represented as a sequence of binary values that correspond to sample amplitudes of the audio signal at each
point in time. These samples are often stored as 8-bit, 16-bit, or 32-bit binary numbers.
 Example: A sound sample with an amplitude of 128 in 8-bit audio.
o 128 in binary is 10000000.
5. Instructions
Machine instructions are represented in binary and are specific to the processor. Each instruction consists of an
"opcode" (operation code) and possibly some additional data (like an address or value).
 Example: An imaginary instruction ADD R1, R2 (add the contents of register R2 to register R1).
o This might be encoded in binary as something like 0001 0001 0010 (specific to the processor
architecture).
These examples show how computers represent different data types in binary. The binary system enables efficient
data storage and processing due to its compatibility with digital circuits
Converting between decimal and binary is a fundamental process in computer science. Let's go over each conversion
method with examples.

2. Number Systems
1. Converting Decimal to Binary
To convert a decimal number to binary, repeatedly divide the number by 2, recording the remainder at each step. The
binary number is formed by reading the remainders in reverse order (from bottom to top).
Steps:
1. Divide the decimal number by 2.
2. Record the remainder (0 or 1).
3. Use the quotient (result of division) as the new number to divide by 2.
4. Repeat until the quotient is 0.
5. The binary number is the sequence of remainders read in reverse.
Example: Convert 25 to binary
1. 25÷2=12 with a remainder of 1.
2. 12÷2=6 with a remainder of 0.
3. 6÷2=3 with a remainder of 0.
4. 3÷2=1 with a remainder of 1.
5. 1÷2=0 with a remainder of 1.
Reading the remainders from bottom to top, 25 in decimal is 11001 in binary.
Another Example converting decimal number 17 to binary

2. Converting Binary to Decimal


To convert a binary number to decimal, use the place value of each binary digit. Each binary place represents a power
of 2, starting from 2^0 at the rightmost bit.
In binary numbers, the rightmost digit is called the Least Significant Bit (LSB), and the leftmost digit is the Most
Significant Bit (MSB).
Steps:
1. Write down the binary number.
2. Starting from the right, multiply each binary digit by 2n2n, where nn is the position of the digit from the right
(starting at 0).
3. Sum all the results to get the decimal equivalent.
Example: Convert 11001 to decimal
1. Identify the position of each bit in 11001: 1,1,0,0,11,1,0,0,1.
2. Multiply each bit by 22 raised to the power of its position:
o 1×24=16
o 1×23=8
o 0×22=0
o 0×21=0
o 1×20=1
3. Sum the values: 16+8+0+0+1=25
So, 11001 in binary is 25 in decimal.
Another Example

2. Octal (Base-8)
Octal uses eight digits: 0 through 7. It is useful as a shorthand representation of binary because each octal digit
corresponds to exactly three binary bits.
 Example:
o Binary: 101011 can be grouped into three bits from the right as 000 101 011.
o Octal: 000 is 0, 101 is 5, and 011 is 3, so the octal number is 053.
o Decimal Equivalent: 0×82+5×81+3×80=0+40+3=43
3. Hexadecimal (Base-16)
Hexadecimal uses sixteen symbols: 0 to 9 and A to F (where A represents 10, B represents 11, and so on up
to F which represents 15). It’s another shorthand for binary, where each hex digit represents four binary bits.
 Example:
o Binary: 11011011 can be grouped into four bits from the right as 1101 1011.
o Hexadecimal: 1101 is D, and 1011 is B, so the hexadecimal number is DB.
o Decimal Equivalent: D×161+B×160=13×16+11=208+11=219

3.Data Storage Units


What is a Bit?
 Bit stands for binary digit.
 It is the smallest unit of data in computing.
 A bit can have one of two values: 0 or 1. These values represent the binary system, which computers use to
process and store information.
What is a Byte?
 A byte is a collection of 8 bits.
 A byte is the basic unit for storing data in computers because it is large enough to represent a single character
(like A or 1).
 For example:
o The letter A is represented in binary as 01000001 (8 bits = 1 byte).
Units of Measurement: From Bytes to Larger Units
As data grows, we need larger units to measure it. Here’s how the hierarchy works:
1. Kilobyte (KB)
o 1 Kilobyte = 1,024 bytes (not 1,000, because computers work in powers of 2. 2^10=1024).
o Example: A small text file or a few paragraphs of text may be around 4 KB.
2. Megabyte (MB)
o 1 Megabyte = 1,024 Kilobytes = 1,048,576 bytes.
o Example: A high-resolution photo may take up 2–5 MB.
3. Gigabyte (GB)
o 1 Gigabyte = 1,024 Megabytes = 1,073,741,824 bytes.
o Example: A full-length HD movie is typically 1–4 GB.
4. Terabyte (TB)
o 1 Terabyte = 1,024 Gigabytes = 1,099,511,627,776 bytes.
o Example: A high-capacity external hard drive may hold 2–5 TB of data.
5. Petabyte (PB)
o 1 Petabyte = 1,024 Terabytes.
o Example: Large-scale data centers use petabytes to measure storage.
Binary vs. Decimal (Why 1,024 and Not 1,000?)
 Computers use the binary system (base 2), where measurements are based on powers of 2.
 In decimal terms, we are accustomed to powers of 10 (1,000, 1 million). However, in computing:
o 1 KB = 2^{10} = 1,024 bytes.
o This is why storage manufacturers often advertise sizes like "1 TB = 1,000 GB," while operating
systems display slightly lower capacities due to binary calculations.
Practical Examples
 Bits: Internet speed is often measured in megabits per second (Mbps). Remember, 1 byte = 8 bits.
 Bytes: File sizes, like a Word document, are measured in bytes, KB, or MB.
 Larger Units: Hard drives, SSDs, and cloud storage are typically measured in GB or TB.
Conversion Table

Binary Addition
The binary system consists of only two digits, 1 and 0. Most of the functionalities of the computer system use
the binary number system.
Before attempting the binary addition process, we should have complete knowledge of how the place works in
the binary number system.
Rules of Binary Addition
0+0=0
0+1=1
1+0=1
1 + 1 =10
How To Do Binary Addition?
Now, look at the example of the binary addition:101 + 101
Procedure for Binary Addition of Numbers:
101
(+) 101
Step 1: First consider the 1’s column, and add the one’s column,( 1+1 ) and it gives the result 10 as per the
condition of binary addition.
Step 2: Now, leave the 0 in the one’s column and carry the value 1 to the 10’s column.
1
101
(+) 101
————–
0
Step 3: Now add 10’s place, 1+( 0 + 0 ) = 1. So, nothing carries to the 100’s place and leave the value 1 in the
10’s place
1
101
(+) 101
————-
10
Step 4: Now add the 100’s place ( 1 + 1 ) = 10. Leave the value 0 in the 100’s place and carries 1 to the 1000’s
place.
1
101
(+) 101
————-
1010
So, the resultant of the addition operation is 1010.
When you cross-check the binary value with the decimal value, the resultant value should be the same.
The binary value 101 is equal to the decimal value 5
So, 5 + 5 = 10
The decimal number 10 is equal to the binary number 1010.
Example 1: 10001 + 11101

Solution:
1
10001
(+) 1 1 1 0 1
———————–
101110
Example 2: 10111 + 110001
Solution:
111
10111
(+) 1 1 0 0 0 1
———————–
1001000

4. Integer Representation in computer systems


This representation determines how integers are stored and manipulated in memory. In computer systems integers are
generally represented in binary format using a fixed number of bits.the main types of representations are
1) Unsigned Integer representation
 Represents only non-negative integers (0 and positive numbers)
 The range of values depends on the number of bits (n): 0 to 2n -1
 Ex: 0000 0, 0001 1, 111115
2) Signed Integer Representation: signed integers can represent both positive and negative numbers.
(a) sign-Magnitude representation
 the MSB indicates the sign of the number. 0  Positive number 1 negative number
 the remaining bits represent the magnitude of the number.
 ex: 0101  +5, 1101  -5

(b) One’s compliment representation


 Positive numbers are represented as unsigned representation.
 Negative numbers are represented by inverting all bits of their positive counterpart.
 Ex: +5  0101 -5  1010
 Issue: two representations for zero (+0 and -0)
(c) Two’s complement representation
 Most widely used representation for signed numbers.
 Negative numbers are represented by taking the two’s compliment (invert all bits and
add 1) of the number.
 To find the two’s complement of the given number, Invert all the bits of the given
number then add 1 .
 Ex: +5  0101 -5= ?
Invert all the bits: 1010, then add 1
1010 +
1
______
1011 so -5  1011
4.Alpha Numeric Character Data - ASCII, EBCDIC, UNICODE
The data entered as characters, number digits, and punctuation are known as alphanumeric data.
Any conversion to numeric form will take place within the computer itself, using software written for this purpose.
For display, the number will be converted back to character form. The conversion between character and number is
also not ‘‘automatic’’ within the computer. There are times when we would prefer to keep the data in character form,
for example, when the numbers represent a phone number or an address to be stored and processed according to text
criteria. Since this choice is dependent on usage within a program, the decision is made by the programmer using rules
specified within the program language being used or by a database designer specifying the data type of a particular
entity.
Since alphanumeric data must be stored and processed within the computer in binary form, each character must be
translated to a corresponding binary code representation as it enters the computer. The choice of code used is
arbitrary. Since the computer does not ‘‘recognize’’ letters, but only binary numbers, it does not matter to the
computer what code is selected.Three alphanumeric codes are in common use. The three codes are known
as Unicode, ASCII , and EBCDIC (Extended Binary Coded Decimal Interchange Code, pronounced ‘‘ebb-see-
dick’’).

ASCII : American Standard Code for Information Interchange


 It is a character encoding standard used to represent text and control characters in computer.
 The ASCII code was originally developed as a standard by the American National Standards Institute (ANSI).
 Represents 128 characters using 7 bits (standard ASCII).
 Extended ASCII uses 8 bits for 256 characters.
 Ex: ‘A’  11000001 , ‘9’ 00111001
 Applications:
 Text Processing: ASCII used to represent text in programming languages and computer systems.
 Data communication: used to transmit data in various communication systems.
 Key Features:
 7 bit encoding allows to represent upto 128 characters.
 Original Character set included.
 English alphabet lowercase , uppercase included.
 Numerals from 0 to 9 are used.
 Common punctuation marks such as comma, period, exclamation mark and others are used.
 Special non-printing characters that are used for controlling text formatting and communication systems.
EBCDIC
 Extended Binary coded Decimal Interchange Code
 It is an 8 –bit alphanumeric code developed by IBM.
 It supports upto 256 unique characters including letters, digits and special symbols.
 It uses non-sequential encoding schemes that is the character codes are not in a straightforward order.
 Applications:
 Text storage : encoding text data in legacy systems.
 Communication: data transmission in specific IBM environments.
 Widely used in processing in older IBM environments.
 Features
 8 bit code : each character is represented by 8 bits,allows 256 unique codes.
 Compatibility: designed for IBM mainframes and system.
 Non-Sequential encoding: the order of alphabetic and numeric codes is not sequential.
 Usage: Primarily used in IBM Systems.
UNICODE
 It is a global character encoding standard used to represent the text.
 Unicode are designed to accommodate nearly every scripting characters, symbols, notations which are
currently in use.
 Unicode transformation formats are variable-length – UTF-8, UTF-16, and UTF-32.
 Key Features:
 It support wide character set.
 It support characters of other modern languages such as Chinese, Arabic, Hindi etc.
 It support variable length encoding as Unicode Transformation Formats(UTF)- UTF-8, UTF-16, and
UTF-32 .
 Each character is assigned with a unique code as numeric value to identify the character.
 It makes an essential standard for global communication.
 Unicode also support wide variety of emojis.
 It maintain consistency when displaying text across different devices.
5.CPU Architecture

1. Introduction to CPU Architecture


The Central Processing Unit (CPU) is the brain of a computer, responsible for executing instructions and
performing calculations. It follows a structured architecture that allows it to process data efficiently.

Major Components of a CPU


1. Arithmetic Logic Unit (ALU):
o Performs arithmetic (addition, subtraction, multiplication, division) and logical (AND, OR, NOT,
XOR) operations.
2. Control Unit (CU):
o Directs operations by fetching, decoding, and executing instructions.
o Manages the flow of data between the CPU, memory, and input/output devices.
3. Registers:
o Small, high-speed storage units inside the CPU for temporary data storage.
o Examples of registers:
 Program Counter (PC): Holds the address of the next instruction.
 Instruction Register (IR): Stores the current instruction.
 Accumulator (ACC): Temporarily holds intermediate results.
 Instruction Register: hold the instruction currently being executed or decoded.
 Memory Address Register (MAR):Holds the address in memory where data is to be fetched
or written
 Memory Data Register (MDR):Holds the data that is being transferred to or from memory.
4. Cache Memory:
o A small-sized, high-speed memory inside the CPU.
o Stores frequently accessed data to improve processing speed.
5. System Bus:
o A set of electrical pathways used for communication between CPU components.
o Types:
 Data Bus: Transfers actual data.
 Address Bus: Transfers memory addresses.
 Control Bus: Sends control signals.

2. CPU Instruction Cycle (Fetch-Decode-Execute Cycle)


The CPU processes instructions in a repeated cycle known as the Fetch-Decode-Execute cycle:
1. Fetch: The control unit retrieves an instruction from memory (RAM) and stores it in the Instruction Register
(IR).
2. Decode: The instruction is analyzed to determine the required operation and operands.
3. Execute: The ALU or other components perform the operation.
4. Store: The result is written back to a register or memory.

6.Basic CPU Architecture – ALU


1. Introduction to CPU Architecture
The Central Processing Unit (CPU) is the main component of a computer that executes instructions and processes
data. It consists of three primary units:
1. Arithmetic Logic Unit (ALU) – Performs mathematical and logical operations.
2. Control Unit (CU) – Directs and coordinates CPU operations.
3. Registers – Temporary storage for instructions and data.
This document focuses on the ALU, one of the most critical components of a CPU.
2. What is the Arithmetic Logic Unit (ALU)?
The Arithmetic Logic Unit (ALU) is a key component of the CPU responsible for performing all arithmetic and
logical operations. It operates as the computational core of the processor.
Functions of ALU
The ALU is responsible for:
1. Arithmetic Operations: Addition, subtraction, multiplication, and division.
2. Logical Operations: AND, OR, NOT, XOR, NAND, NOR, XNOR.
3. Bitwise Operations: Bit shifting (left shift, right shift) and bit manipulation.
4. Comparison Operations: Checking if values are equal, greater than, or less than.
5. Increment/Decrement Operations: Increasing or decreasing values by one.
3. Components of ALU
The ALU consists of various subcomponents that work together to perform computations:
(i) Operand Registers/ Input registers
 Temporarily store the input values for an operation.
 Examples: Accumulator (ACC), General Purpose Registers (R1, R2, etc.)
(ii) Arithmetic Unit
 Performs mathematical calculations like addition, subtraction, multiplication, and division using circuits
like adders and multipliers.
(iii) Logic Unit
 Executes logical operations such as AND, OR, XOR, and NOT using logic gates.
(iv) Status Flags
 Stores information about the result of an operation.
 Example flags:
o Zero (Z) Flag: Set if the result is zero.
o Carry (C) Flag: Set if there is a carry from an addition operation.
o Sign (S) Flag: Set if the result is negative.
o Overflow (V) Flag: Set if an arithmetic operation causes an overflow.
(v) Output Registers
 Hold the result of the operation
4. Working of ALU
The ALU follows a systematic process for executing instructions:
Step 1: Input Fetching
 The Control Unit (CU) fetches the instruction from memory and sends required data to the ALU.
Step 2: Operation Execution
 The ALU performs the required arithmetic or logical operation on the input values.
Step 3: Result Storage
 The computed result is stored in the Accumulator (ACC) or a register.
 If necessary, the result is sent back to memory.
Step 4: Flag Update
 The status flags (Zero, Carry, Sign, Overflow) are updated based on the result.
5. Role of ALU in CPU Performance
 The speed of ALU operations directly affects CPU performance since most computing tasks involve
arithmetic and logic calculations.
 Modern CPUs may have multiple ALUs to perform operations in parallel, increasing processing efficiency.
 ALUs are designed using combinational logic circuits such as full adders, multiplexers, and logic gates.

7.Registers and Control Unit


1.Registers in CPU
Definition:
Registers are small, high-speed storage units located inside the CPU, used to store temporary data, instructions, and
addresses.
Characteristics of Registers:
 Faster than cache and main memory.
 Store data temporarily for quick processing.
 Used in the fetch-decode-execute cycle for efficient execution.
Types of Registers:
1. General-Purpose Registers (GPRs)
o Used for general data storage during execution.
o Example: AX, BX, CX, DX (in x86 architecture).
2. Special-Purpose Registers
o Designed for specific tasks, such as holding memory addresses, flags, or counters.
Special-Purpose Registers in a CPU:

Register Function

Program Counter (PC) Holds the address of the next instruction to be executed.

Instruction Register (IR) Stores the current instruction being executed.

Memory Address Register (MAR) Holds the address of the memory location being accessed.
Register Function

Memory Data Register (MDR) Temporarily stores data read from or written to memory.

Accumulator (ACC) Holds intermediate arithmetic and logical results.

Stack Pointer (SP) Points to the top of the stack in memory.

Status/Flag Register Stores flags indicating CPU status (e.g., Zero Flag, Carry Flag, Overflow Flag).

Importance of Registers in CPU Operations:


 Enable fast data retrieval and processing.
 Reduce dependence on slower memory (RAM).
 Facilitate efficient execution of instructions.

2. Control Unit (CU)


Definition:
The Control Unit (CU) is a critical component of the CPU that directs the execution of instructions by coordinating
data flow between the CPU, memory, and input/output devices.
Functions of the Control Unit:
1. Instruction Fetching – Retrieves instructions from memory.
2. Instruction Decoding – Interprets the instructions to determine required operations.
3. Generating Control Signals – Directs other CPU components, such as the ALU and registers.
4. Managing Data Flow – Ensures proper movement of data between registers, memory, and I/O devices.
5. Communication with ALU: Manage interactions for arithmetic and logic calculations.
6. Manage Registers: to ensure the registers store and transfer the required data and instructions during program
execution.
7. Coordination with input and output devices: to ensure the correct data is sent to and received from the
appropriate devices.
Types of Control Units:
1. Hardwired Control Unit:
o Uses fixed logic circuits to generate control signals.
o Faster but less flexible.
o Used in RISC (Reduced Instruction Set Computing) processors.
2. Microprogrammed Control Unit:
o Uses a control memory to store microinstructions.
o More flexible but slightly slower.
o Used in CISC (Complex Instruction Set Computing) processors.

3. Role of Registers and Control Unit in the Instruction Cycle


The Fetch-Decode-Execute Cycle is controlled by the CU and assisted by registers:
1. Fetch Phase:
o The Program Counter (PC) sends the address of the next instruction to the Memory Address
Register (MAR).
o The instruction is retrieved from memory and placed in the Instruction Register (IR).
2. Decode Phase:
o The Control Unit (CU) interprets the instruction in the IR and prepares control signals.
3. Execute Phase:
o The ALU processes the instruction using data from registers.
o The Control Unit sends signals to store results in appropriate locations.
4. Store Phase:
o The result is stored in a register or memory for further processing.
8. BUS

A bus is a set of physical connections (cables, circuits, etc.) that can be shared by multiple hardware
components to communicate with one another.
Memory and input/ output devices are connected to the Central Processing Unit through a group of
lines called a bus. These lines are designed to transfer data between different components.

Types of Computer Bus


 Address Bus: carries the addresses of memory locations to be accessed by the CPU.It tells the system
where data should be read from or written to in memory. The address bus is unidirectional from the
CPU to the memory.

 Data Bus: The data bus is responsible for the actual transfer of data between the CPU, memory,
and peripheral devices. It carries the data that the system reads from or writes to memory or I/O
devices. The data bus is bidirectional.
 Control Bus: carries control signals that manage and synchronize the operations of the CPU, memory,
and peripheral devices. The control bus is unidirectional.

9. Addressing in Computers
Addressing refers to the method of specifying the location of data or instructions within the computers
memory.
Types of addressing modes:
1. physical addressing: This is the most common addressing mode. In this address is directly mapped to
a specific physical memory location in the RAM.
2. Logical addressing:
3. Immediate addressing
4. Direct addressing:
5. Indirect Addressing:
6. Register Addressing:
7. Indexed addressing:
8. Base – Register Addressing:
9. Relative Addressing

9.Instruction Format and Assembly Language


1. Instruction Format
Definition:
An Instruction Format defines the structure and layout of an instruction in a CPU’s instruction set. It specifies how
the instruction is encoded in binary and interpreted by the processor.
Components of an Instruction Format:
1. Opcode (Operation Code) – Specifies the operation to be performed (e.g., ADD, MOV).
2. Operands – Specifies the data or memory location(s) involved in the operation.
3. Addressing Mode – Defines how the operands are accessed (registers, memory, immediate values).
2. Types of Instruction Formats
Different CPU architectures use different instruction formats. The most common types are:
(i) Zero-Address Instructions
 No explicit operands; operates on an implicit stack.
 Example: PUSH, POP, ADD (in Stack-based machines)
(ii) One-Address Instructions
 One operand is specified; the other is stored in an accumulator.
 Example: ADD A (adds A to the accumulator)
(iii) Two-Address Instructions
 Both source and destination operands are specified.
 Example: MOV A, B (copies B into A)
(iv) Three-Address Instructions
 Three operands are explicitly mentioned, useful for complex calculations.
 Example: ADD A, B, C (A = B + C)
(v) Variable-Length Instructions
 Instruction length varies based on the operation and addressing mode.
 Found in Complex Instruction Set Computing (CISC) processors.
(vi) Fixed-Length Instructions
 Every instruction has the same length (e.g., 32-bit).
 Common in Reduced Instruction Set Computing (RISC) processors.
3. Assembly Language
Definition:
Assembly Language is a low-level programming language that uses human-readable mnemonics instead of binary
machine code. It provides direct control over CPU operations. It is an intermediate language between high-level and
machine language.
Features of Assembly Language:
 Uses mnemonics like MOV, ADD, SUB instead of binary codes.
 It provide a way to write efficient programs.
 Requires an Assembler to convert assembly code into machine code.
 Allows direct memory and register manipulation.
 It offer a direct control over the hardware.
 Faster than high-level languages but harder to code.
Advantages of Assembly Language:
 Efficient and fast execution.
 Direct Hardware Control
 Suitable for system Programming (OS,drivers)
Disadvantages of Assembly Language:
 Difficult to learn compared to high-level languages.

 Machine-dependent (not portable).


Basic components of Assembly Language
1. Instructions: it specifies the operation that CPU can perform.
2. Operands: It specify the data that the operation will work on.
3. Directives: It provide the information to the assembler.

4. Basic Assembly Language Instructions


(i) Data Transfer Instructions: Move data between registers memory and i/o devices.
 MOV A, B – Move data from B to A.
 LOAD A, [1000H] – Load value from memory address 1000H to A.
 STORE A, [2000H] – Store A’s value at memory address 2000H.
(ii) Arithmetic Instructions: to perform mathematical operations
 ADD A, B – Add B to A.
 SUB A, B – Subtract B from A.
 MUL A, B
 DIV A, B
 INC A – Increment A by 1.
 DEC A
(iii) Logical Instructions:
 AND A, B – Perform bitwise AND on A and B.
 OR A, B – Perform bitwise OR on A and B.
 XOR A, B – Perform bitwise XOR on A and B.
(iv) Control Transfer (Branching) Instructions
1. Unconditional Jump Instruction
 JUMP LABEL – Unconditional jump to LABEL..
 CALL SUBROUTINE – Call a function.
2. Conditional Jump Instruction
 JE LABEL – Jump if equal
 JNE Label- Jump Not Equal
 JG Label – Jump Greater: Jump if the first operand was greater than the second operand.
 JL Label – Jump Less : Jump if the first operand was lesser than the second operand.
 JGE label – Jump Greater than or equal to: Jump if the first operand was Greater than or equal to the second
operand.
 JLE Label: Less than or equal to : Jump if the first operand was less than or equal to the second operand.
V) comparison Instructions : comparison instructions are used to compare two operands and set the status flags
based on the result of the comparison.
CMP A, B
If A=B Zero Flag will Set
A>B Carry Flag Will be cleared
A<B Carry Flag will be set

vi) Shift Instructions


SHL A, 1
SHR A,1
5. Example of Assembly Language Program
Example: Adding Two Numbers
Assembly:
MOV AL, 05H ; Load 5 into AL register
MOV BL, 03H ; Load 3 into BL register
ADD AL, BL ; Add BL to AL
MOV CL, AL ; Store result in CL
Explanation:
1. MOV AL, 05H – Load the value 5 into register AL.
2. MOV BL, 03H – Load the value 3 into register BL.
3. ADD AL, BL – Add BL to AL (Result: AL = 8).
4. MOV CL, AL – Store the result in CL.

10. Instruction Cycle – Fetch and Execute Cycle


1. Introduction to Instruction Cycle
Definition:
The Instruction Cycle is the sequence of steps followed by the CPU to execute an instruction stored in memory. It is
also known as the Fetch-Decode-Execute Cycle or simply the Fetch-Execute Cycle.
Steps in the Instruction Cycle:
The CPU follows four main steps in an instruction cycle:
1. Fetch – Retrieves the instruction from memory.
2. Decode – Interprets the instruction to determine the required operation.
3. Execute – Performs the required operation.
4. Store (Write-back) – Saves the result (if necessary).
The Fetch and Execute steps are the most critical in this cycle.
2. Fetch Cycle
Purpose:
The Fetch Cycle is responsible for retrieving the instruction from memory so that it can be executed.
Steps of the Fetch Cycle:
1. Program Counter (PC) → Memory Address Register (MAR)
o The PC holds the address of the next instruction.
o The address is copied into the MAR.
2. Memory → Instruction Register (IR)
o The CPU requests data from the memory at the address in the MAR.
o The retrieved instruction is stored in the IR.
3. Increment the Program Counter (PC)
o The PC is updated to point to the next instruction in sequence.
Diagram Representation of Fetch Cycle:
PC → MAR → Memory → IR
Increment PC
3. Decode Cycle
Purpose:
The instruction stored in the Instruction Register (IR) is interpreted to determine the operation to be performed.
Steps of the Decode Cycle:
1. The Control Unit (CU) reads the instruction from the IR.
2. The instruction is broken down into Opcode (operation) and Operands (data/memory addresses).
3. The CU generates the necessary control signals for execution.
4. Execute Cycle
Purpose:
The CPU performs the actual operation specified by the instruction.
Steps of the Execute Cycle:
1. The ALU processes the instruction if it involves arithmetic or logical operations.
2. Data may be moved between registers or memory locations.
3. The result is stored in a register or memory, if needed.
Example Operations:
Instruction Operation Performed

ADD A, B A = A + B

MOV A, B Copy value of B into A

JMP 100H Jump to memory location 100H


5. Store (Write-Back) Cycle
Purpose:
If the instruction modifies data, the result is stored back into memory or a register.
Steps of the Store Cycle:
1. The computed result is stored in the Memory Data Register (MDR).
2. The result is written to a register or memory location.
6. Complete Instruction Cycle (Fetch-Decode-Execute-Store)
The complete cycle follows this sequence:
1. Fetch the instruction from memory.
2. Decode the instruction to understand its operation.
3. Execute the operation using ALU or registers.
4. Store the result (if needed) back to memory.
7. Example of an Instruction Cycle
Instruction: ADD A, B (Add contents of B to A)
1. Fetch: CPU fetches ADD A, B from memory.
2. Decode: Control Unit identifies it as an addition operation.
3. Execute: ALU adds values of A and B.
4. Store: Result is stored in A.

You might also like