Foc M2
Foc M2
MODULE - 2
1
13-05-2025
NUMBER SYSTEMS
2
13-05-2025
3
13-05-2025
4
13-05-2025
5
13-05-2025
6
13-05-2025
7
13-05-2025
8
13-05-2025
9
13-05-2025
Practice Problems
1. 294 - 100100110
2. 160 - 10100000
3. 17 - 10001
4. 195.25 - 11000011.01
5. 244.5 - 11110100.1
6. 76.75 - 1001100.11
7. 891 - 1101111011
8. 57 - 111001
9. 59 - 111011
10. 82 - 1010010
11. 175 - 10101111
12. 48 - 110000
13. 253 - 11111101
14. 52.5 - 110100.1
15. 25.75 - 11001.11
16. 333.33 - 101001101.0101
10
13-05-2025
Practice Problems
1. 294 - 100100110
2. 160 - 10100000
3. 17 - 10001
4. 195.25 - 11000011.01
5. 244.5 - 11110100.1
6. 76.75 - 1001100.11
7. 891 - 1101111011
8. 57 - 111001
9. 59 - 111011
10. 82 - 1010010
11. 175 - 10101111
12. 48 - 110000
13. 253 - 11111101
14. 52.5 - 110100.1
15. 25.75 - 11001.11
16. 333.33 - 101001101.0101
11
13-05-2025
12
13-05-2025
13
13-05-2025
Practice Problems
1. 0110101 - 53
2. 10100011 - 163
3. 11101111 - 239
4. 1011010.11 - 90.75
5. 111001010.10 - 458.5
6. 11101 - 29
7. 1010101 - 85
8. 100111 - 39
Practice Problems
1. 0110101 - 53
2. 10100011 - 163
3. 11101111 - 239
4. 1011010.11 - 90.75
5. 111001010.10 - 458.5
6. 11101 - 29
7. 1010101 - 85
8. 100111 - 39
14
13-05-2025
15
13-05-2025
16
13-05-2025
Practice problems
1. 98 - 142
2. 210 - 322
3. 136 - 210
4. 1792 - 3400
5. 127.3 - 177.231
6. 52.8 - 64.631
7. 100.5 - 144.4
8. 212 - 324
Practice problems
1. 98 - 142
2. 210 - 322
3. 136 - 210
4. 1792 - 3400
5. 127.3 - 177.231
6. 52.8 - 64.631
7. 100.5 - 144.4
8. 212 - 324
17
13-05-2025
Practice Problems
1. 215 - 141
2. 125 - 85
3. 275 - 189
4. 23 - 19
5. 770 - 504
6. 163.5 - 115.625
7. 23.6 - 19.75
8. 152.7 - 106.875
18
13-05-2025
Practice Problems
1. 215 - 141
2. 125 - 85
3. 275 - 189
4. 23 - 19
5. 770 - 504
6. 163.5 - 115.625
7. 23.6 - 19.75
8. 152.7 - 106.875
19
13-05-2025
20
13-05-2025
Practice Problems
1. 256 - 100
2. 4568 - 11D
3. 958.93 - 3BE.EE14
4. 578 - 242
5. 347 - 15B
6. 528 - 210
7. 121.56 - 79.8F5
8. 623.12 - 26F.1EB
Practice Problems
1. 256 - 100
2. 4568 - 11D8
3. 958.93 - 3BE.EE14
4. 578 - 242
5. 347 - 15B
6. 528 - 210
7. 121.56 - 79.8F5
8. 623.12 - 26F.1EB
21
13-05-2025
Practice Problems
1. 2AF.4C - 687.296
2. 38E - 910
3. 5B - 91
4. 3F.12 - 63.070
5. 83.B - 130.687
6. 12D.3 - 301.187
7. 11C - 284
8. 78 - 120
22
13-05-2025
Practice Problems
1. 2AF.4C - 687.296
2. 38E - 910
3. 5B - 91
4. 3F.12 - 63.070
5. 83.B - 130.687
6. 12D.3 - 301.187
7. 11C - 284
8. 78 - 120
SIGNED INTEGER
REPRESENTATION
23
13-05-2025
24
13-05-2025
25
13-05-2025
26
13-05-2025
27
13-05-2025
11111010 11111011
28
13-05-2025
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23
-23
+45
-45
+39
-39
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23 00010111
-23 00010111
+45 00101101
-45 00101101
+39 00100111
-39 00100111
29
13-05-2025
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23 00010111 00010111
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23 00010111 00010111
30
13-05-2025
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23 00010111 00010111
Practice Problems
Number Binary Sign 1’s 2’s
representation Magnitude Complement Complement
+23 00010111 00010111 00010111 00010111
31
13-05-2025
BINARY ARITHMETIC
32
13-05-2025
33
13-05-2025
Subtraction Rules
34
13-05-2025
35
13-05-2025
36
13-05-2025
Binary Division
37
13-05-2025
38
13-05-2025
39
13-05-2025
Bit
◦ A bit is the smallest and basic unit of information in computing and
digital communications.
◦ It can have only one of two values.
◦ The most common representation of these values are 0 and 1.
◦ The term bit is a contraction of binary digit (0 or 1).
Byte
◦ Bits are often grouped together in 8-bit clusters called bytes.
◦ Since a byte contains eight bits that each have two possible values, a single
byte may have 28 or 256 different values.
◦ The byte was the number of bits used to encode a single character of text in a
computer and for this reason it is the smallest addressable unit of memory in
many computer architectures.
40
13-05-2025
Kilo Byte
◦ A unit of computer memory or data storage capacity equal to 1,024 (210)
bytes.
◦ 1 KB = 1024 bytes = 210 B is the definition used by Microsoft Windows
and Linux for computer memory, e.g., RAM
◦ Kilo bytes are used to measure small file such as text files.
Mega Byte
◦ The megabyte is a multiple of the unit byte for digital information storage or
transmission with three different values depending on context 1048576 bytes
(220).
◦ Generally for computer memory; one million bytes generally for computer
storage or transmission rates.
◦ The term "megabyte" is commonly used to mean either 10002 bytes or 1024
kilobytes.
◦ Mega bytes are used to measure the size of the larger files like images, audio
files an software applications.
41
13-05-2025
Giga Byte
◦ The unit symbol for the gigabyte is GB.
◦ A unit of computer memory or data storage capacity equal to 1,024 megabytes
(230bytes) or One billion bytes.
◦ Giga bytes are commonly used to measure the storage capacity of devices like
smartphones , SSDs, and hard drives.
Tera Byte
◦ A terabyte (TB) is a measure of computer storage capacity that is 2 to the 40th
power or approximately a trillion bytes (that is, a thousand gigabytes).
◦ The prefix tera is derived from the Greek word for monster.
◦ The unit symbol for the terabyte is TB.
◦ 1 TB = 1000000000000bytes = 240 bytes = 1024 gigabytes.
◦ Tera bytes are commonly used to measure the storage capacity of devices SSDs,
and hard drives etc.
42
13-05-2025
◦ Numbers
◦ Whole number, fractional number, …
◦ Text
◦ ASCII code, Unicode
◦ Audio
◦ Image and graphics
◦ Video
43
13-05-2025
Representing Text
87
44
13-05-2025
ASCII code
◦ ASCII Code (American Standard Code for Information Interchange)
◦ ASCII is a character encoding standard used to represent text in computers,
communication systems, and other electronic devices.
◦ It assigns a unique numerical value to each character, making it possible for
computers to store and process textual data in a standardized way.
◦ Developed in 1963 by the American National Standards Institute (ANSI).
◦ Originally based on telegraph codes.
◦ The first version was 7-bit ASCII (0–127 characters).
◦ Later extended to 8-bit ASCII (Extended ASCII), which includes 256 characters
(0–255) to support more symbols and international characters.
89
ASCII code
◦ Standard ASCII (7-bit: 0–127)
◦ Control Characters (0–31, 127): Used for text formatting and communication
control (e.g., newline, carriage return, backspace).
◦ Printable Characters (32–126): Includes letters, digits, punctuation marks, and
special symbols.
◦ Extended ASCII (8-bit: 128–255)
◦ Includes accented letters (é, ü, ñ), mathematical symbols, and box-drawing
characters for graphical interfaces.
45
13-05-2025
Example
◦ 72 → 'H'
◦ 101 → 'e'
◦ 108 → 'l'
◦ 108 → 'l'
◦ 111 → 'o'
Thus, "Hello" is stored as 72 101 108 108 111 in ASCII.
46
13-05-2025
ASCII code
93
47
13-05-2025
48
13-05-2025
• Uses 4 bytes per character, making it simple but inefficient for storage.
◦ Examples:
•'A' → U+0041
49
13-05-2025
CPU ARCHITECTURE
50
13-05-2025
51
13-05-2025
52
13-05-2025
3. Registers
• A register is a single, permanent storage location within the CPU
used for a particular, defined purpose.
• A register is used to hold a binary value temporarily for storage, for
manipulation, and/or for simple calculations.
• Most instructions are executed by the sequenced movement of
data between the different registers in the ALU and the control unit.
◦ Most registers support four primary types of operations:
1. Registers can be loaded with values from other locations, in
particular from other registers or from memory locations.
53
13-05-2025
3. Registers continued…
2. Data from another location can be added to or subtracted
from the value previously stored in a register, leaving the sum or
difference in the register.
3. Data in a register can be shifted or rotated right or left by one
or more bits. This operation is important in the implementation
of multiplication and division.
4. The value of data in a register can be tested for certain
conditions, such as zero, positive, negative, or too large to fit in
the register.
54
13-05-2025
55
13-05-2025
4. Bus System
◦ The bus system is used for communication between the CPU and
other parts of the computer, such as memory and input/output
devices.
◦ The different types of buses are:
◦ Data Bus: Carries the actual data between the CPU, memory,
and I/O devices.
◦ Address Bus: Carries memory addresses to specify locations in
memory.
◦ Control Bus: Carries control signals to coordinate the operations
of the CPU, memory, and peripherals.
56
13-05-2025
5. Clock
◦ The clock generates periodic pulses that synchronize the CPU's
operations, ensuring that instructions are executed at a specific
rate (clock cycle).
◦ It controls the timing of all operations within the CPU.
ASSEMBLY
LANGUAGE
57
13-05-2025
Assembly language
◦ Assembly language is a low-level programming language that is
closely related to the architecture of a computer's CPU.
◦ It is a human-readable representation of machine code
instructions, which are directly executed by the CPU.
◦ It uses mnemonics to represent the operations that a processor
has to do.
◦ It is an intermediate language between high-level languages like
Python and the machine language.
58
13-05-2025
Assembly language
◦ An assembler is used to convert assembly code into machine
language.
◦ That machine code is stored in an executable file for the sake of
execution.
◦ Assembly language is made up of a set of symbolic instructions
that are mapped to the underlying machine code of a
processor.
59
13-05-2025
Components of an Instruction
◦ Instructions(opcode): Each instruction in assembly language
corresponds to an operation that the CPU can perform (e.g.,
moving data, performing arithmetic, jumping to different parts of
code).
Assembly language
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).
60
13-05-2025
61
13-05-2025
TYPES OF
INSTRUCTIONS
Based On Operation Type
62
13-05-2025
LOAD Instruction
• The LOAD instruction moves data from memory to a register.
• It is typically used when the CPU needs to use a value stored in
memory.
• Example (Assembly - General Representation)
LOAD R1, 1000
◦ Load the value from memory address 1000 into register R1
◦ Example (x86 Assembly)
MOV AX, [1000H]
◦ Load data from memory address 1000H into register AX
STORE Instruction
•The STORE instruction moves data from a register to memory.
•It is used when the CPU needs to save a computed result back into
memory.
◦ Example (Assembly - General Representation)
STORE R1, 2000
◦ Store the value in register R1 into memory address 2000
◦ Example (x86 Assembly)
MOV [2000H], AX
◦ Store the value in AX into memory address 2000H
63
13-05-2025
Arithmetic Instructions
•Arithmetic instructions are a category of CPU instructions used to
perform basic arithmetic operations, such as addition, subtraction,
multiplication, and division, on data stored in registers or memory.
•These operations are fundamental to most computations performed
by a computer.
•Examples:
•ADD, SUB, MUL, DIV etc.
ADD Instruction
◦ The ADD instruction performs addition between two operands and stores the
result in a destination register.
◦ Example (Assembly - General Representation)
ADD destination, source
◦ Adds the source value to the destination register.
◦ Example (x86 Assembly)
MOV AX, 5 ; Load 5 into AX
MOV BX, 3 ; Load 5 into BX
ADD AX, BX ; AX = AX + BX (AX now holds 8)
◦ Here, the value in register BX is added to the value in register AX and the result
is stored in AX.
64
13-05-2025
SUB Instruction
◦ The SUB instruction performs subtraction between two operands and
stores the result in the destination register.
◦ Example (Assembly - General Representation)
SUB destination, source
◦ Subtracts the source value from the destination register.
◦ Example (x86 Assembly)
MOV AX, 5 ; Load 5 into AX
MOV BX, 3 ; Load 5 into BX
SUB AX, BX ; AX = AX - BX (AX now holds 2)
◦ Here, the value in register BX is subtracted from the value in register AX and
the result is stored in AX.
Logical Instructions
◦ Logical instructions in assembly language perform bitwise
operations on data.
65
13-05-2025
AND Instruction
◦ The AND instruction performs a bitwise AND operation between
two operands.
◦ It compares corresponding bits of both operands and sets the
result bit to 1 only if both input bits are 1. Otherwise, it sets the
result bit to 0.
AND Instruction
◦ Syntax (General Representation)
AND Destination, Source
◦ Destination = Destination AND Source
◦ Example (x86 Assembly)
MOV AL, 0AH ; AL = 00001010 (Binary)
MOV BL, 06H ; BL = 00000110 (Binary)
AND AL, BL ; AL = AL AND BL
; Result = 00000010 (Binary) = 02H
66
13-05-2025
OR Instruction
◦ The OR instruction performs a bitwise OR operation between two
operands.
◦ It compares corresponding bits of both operands and sets the
result bit to 1 if at least one of the input bits is 1.
OR Instruction
◦ Syntax (General Representation)
OR Destination, Source
◦ Destination = Destination OR Source
◦ Example (x86 Assembly)
MOV AL, 0AH ; AL = 00001010 (Binary)
MOV BL, 06H ; BL = 00000110 (Binary)
OR AL, BL ; AL = AL OR BL
; Result = 00001110 (Binary) = 0EH
67
13-05-2025
Single-operand Instructions
◦ Single-operand arithmetic instructions perform operations on a
single register or memory location (unlike two-operand
instructions that involve both a source and a destination).
68
13-05-2025
69
13-05-2025
70
13-05-2025
71
13-05-2025
72
13-05-2025
TYPES OF
INSTRUCTIONS
Based On Number of Operands
CPU Instructions
◦ CPU instructions can also be classified based on how many operands
(sources or destinations) they use.
• Unary Instructions: These instructions involve only one operand.
• Example: NOT R1 (negates the value in register R1)
• Binary Instructions: These instructions work with two operands.
• Example: ADD R1, R2 (adds the contents of R1 and R2)
• Ternary Instructions: These instructions involve three operands.
• Example: MUL R1, R2, R3 (multiply R1 and R2, store the result in R3)
73
13-05-2025
INSTRUCTION CYCLE
While this cycle can vary from CPU to CPU, they typically consist
of the following stages:
74
13-05-2025
1. Fetch
Programs reside in the memory, entered through input devices
PC (Program counter) has address of the first instruction or next
instruction to be executed.
The contents of PC are transferred to MAR (Memory Address Register)
and send over system bus to memory.
A Read signal is sent to the memory by control unit.
The instruction (addressed word) is fetched and loaded into MDR
(Memory Data Register) after duration of memory access time.
The contents of MDR transferred to IR (Instruction Register).
Now the instruction is ready to be decoded and executed.
2. Decode
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 CPU prepares necessary resources (registers, ALU, memory, etc.).
4. The CU generates the necessary control signals for execution.
75
13-05-2025
3. Execute
The CPU performs the operation (e.g., arithmetic, logic
operations, memory access).
Get operands for ALU from:
General-purpose register (R0, … Rn-1)
Memory (address to MAR, Read from memory, data to
MDR, and then to ALU)
The Arithmetic Logic Unit (ALU) executes the instruction if it
involves calculations.
Updates flag bits in the flag register.
Flag Register
76
13-05-2025
4. Store (Write-back)
Store the result back to:
General-purpose register (R0, … Rn-1)
Memory (address to MAR, result to MDR, Write to memory)
77
13-05-2025
KEY COMPONENTS
78
13-05-2025
INSTRUCTION CYCLE OF
ADD INSTRUCTION
79
13-05-2025
ADD AL, BL ; AL = AL + BL
80
13-05-2025
◦ Operations:
1. ALU ← AL + BL (Perform addition)
2. Flags Updated:
•Zero Flag (ZF): Set if the result is 0.
•Carry Flag (CF): Set if there is a carry out.
81
13-05-2025
INSTRUCTION WORD
FORMAT
82
13-05-2025
83
13-05-2025
ADDRESSING
MODES
Addressing Modes
• The various ways of addressing registers and memory are
known as addressing modes.
84
13-05-2025
Addressing Modes
Immediate Addressing Mode
• MOV AX, 1234H
Register Addressing Mode
• The operand is stored in a register.
• MOV AX, BX
Direct Addressing Mode
• The memory address is directly specified in the instruction.
• MOV AX, [2000H] ; Load value from memory address 2000H into AX
• MOV [3000H], AL Store AL into memory address 3000H
COMMON
CPU ARCHITECTURES
85
13-05-2025
In CISC, a single instruction can execute multiple low- level operations
(such as loading from memory, performing an arithmetic operation,
and storing the result back to memory) in a single instruction cycle.
86
13-05-2025
87