CA Unit-2
CA Unit-2
ADDRESSING MODES:
In computer architecture, addressing modes are mechanisms that determine how the
operands of an instruction are accessed. It specifies the way in which the processor
interprets the address or location of an operand in memory or a register.
Instructions in a computer's instruction set architecture (ISA) typically have one or more
operands, which can be data values or memory addresses.
The addressing mode determines how the processor calculates or determines the effective
address of an operand. The effective address is the actual location where the data is
stored or retrieved.
Types of addressing modes:
1. Register Mode: The operand is specified by a register's content.
Example: ADD R1, R2 (Add the content of register R2 to the content of register R1)
2. Immediate Mode: The operand is directly specified within the instruction itself.
Example: ADD R1, #5 (Add the immediate value 5 to the content of register R1)
3. Direct Mode: The operand is the address of a memory location where the data resides.
Example: LOAD R1, [1000] (Load content of memory location 1000 into register R1)
4. Indirect Mode: The operand contains the address of a memory location that holds the
actual address of the data.
Example: LOAD R1, [R2] (Load the content of the memory location whose address is
stored in register R2 into register R1)
1
5. Indexed Mode: The operand is obtained by adding a constant or a register value to a
base address. This mode is often used for accessing elements in arrays or data structures.
Example: LOAD R1, [R2+5] (Load the content of the memory location at the address
R2+5 into register R1)
6. Implied Mode: It is also called inherent/implicit addressing mode. The operand is
implied by the instruction. The operand is hidden/fixed inside the instruction. Example:
Complement Accumulator CMA (Here accumulator A is implied by the instruction).
Complement Carry Flag CMC (Here Flags register is implied by the instruction)
Set Carry Flag STC (Here Flags register is implied by the instruction)
7. Relative Mode: The effective address of the operand is obtained by adding the address
of the program counter with the address part of the instruction.
Effective Address = Value of PC + Address part of the instruction
Example: JMP 100 (Perform an unconditional jump to the instruction located at the
address PC+100)
8. Stack Mode: The operand is accessed from the top of the stack.
Example: POP R1 (Pop the top value from the stack and store it in register R1)
9. Auto-Increment Mode: The operand is accessed from a memory location, and the
address is automatically incremented after the access.
Example: LOAD R1, [R2++] (Load the content of the memory location at the address
stored in R2 into register R1 and then increment R2)
10.Auto-Decrement Mode: The operand is accessed from a memory location, and the
address is automatically decremented after the access.
Example: LOAD R1, [--R2] (Decrement R2 and then load the content of the memory
location at the new address into register R1)
Detail explanation of 5 addressing mode which are in syllabus:
REGISTER, IMMEDIATE, DIRECT, INDIRECT, INDEXED.
2
1. REGISTER ADDRESSING MODES:
Register addressing mode is a type of addressing mode used in computer architectures
where the operand is specified as a register.
In this mode, the instruction operates directly on the contents of specified register,
without the need to access memory. It is one of the simplest and most efficient addressing
modes.
In this mode, the instruction specifies the source and/or destination registers where the
data is stored or retrieved.
The data is manipulated within the registers themselves, which are small, high-speed
storage locations within the processor.
Example: ADD R1, R2
In this instruction, the ADD operation adds the contents of register R2 to the contents of
register R1. The result is stored back in register R1.
Here's how the Register Addressing Mode works:
1. Instruction Fetch: The processor fetches the instruction from memory, which contains
the opcode (operation code) and register operands.
2. Decode: The processor decodes the instruction to determine the operation to be
performed and the registers involved.
3. Operand Access: The processor accesses the source registers specified in the
instruction. It retrieves the contents of these registers from the register file, which is a
set of registers within the processor.
4. Operation: The processor performs specified operation on the data within the source
registers. In the case of our example, it adds the contents of R2 to the contents of R1.
5. Result Store: The processor stores the result of the operation back into the destination
register, which is R1 in this case.
Advantages of Register Addressing Mode:
1. Speed: Register operations are typically faster than memory operations because
registers are located within the processor and have very fast access times. This improves
the overall execution speed of the instruction.
2. Efficiency: Register operations do not require accessing memory, which reduces the
memory access time. It saves memory-related instructions and reduces memory traffic.
3. Code Size: Using registers directly as operands in instructions helps in reducing the size
of the instruction code. Since registers are represented by small identifiers, fewer bits
are needed to specify them compared to memory addresses.
3
Disadvantages of Register Addressing Mode:
1. Limited Register Space: Processors have a limited number of registers available for
use. Depending on the architecture, the number of registers can range from a few to
several dozen. Therefore, register addressing mode may impose limitations on the
complexity and size of programs.
2. Data Sharing: Since registers are shared resources, multiple instructions may require
the same register for their operations. This can lead to register conflicts or dependencies
that need to be managed by the processor.
1. ARITHMATIC OPERATIONS:
Arithmetic operations in computer architecture refer to the set of instructions that perform
mathematical calculations on data within the central processing unit (CPU). These
instructions operate on numerical data, such as integers or floating-point numbers, and
allow CPU to perform tasks like addition, subtraction, multiplication, and division.
Here are some common arithmetic operations found in an instruction set:
1. Addition (ADD): The ADD instruction adds two values together and stores the result
in a destination location. For example,
ADD R1, R2 adds the contents of register R1 and R2, and stores the sum in register R1.
2. Subtraction (SUB): The SUB instruction subtracts one value from another and stores
the result in a destination location. For example,
SUB R1, R2 subtracts the content of register R2 from R1, and stores the difference in
register R1.
3. Multiplication (MUL): The MUL instruction multiplies two values together and stores
the product in a destination location. For example,
MUL R1, R2 multiplies the content of register R1 and R2, and stores the result in
register R1.
4. Division (DIV): The DIV instruction divides one value by another and stores the
quotient in a destination location. For example,
DIV R1, R2 divides the content of register R1 by R2, and stores quotient in register R1.
9
5. Increment (INC) and Decrement (DEC): These instructions increment or decrement
the value of a register or memory location by one. For example, INC R increases content
of register R1 by one. DEC R decreases content of register R1 by one.
6. Negation (NEG): This instruction changes sign of a value, by multiplying it by -1.
7. Overflow and Carry Operations: These operations handle overflow and carry
conditions that may occur during arithmetic operations. They set flags or registers to
indicate whether an operation resulted in overflow or carry.
2. LOGICAL OPERATIONS:
Logical operations refer to the set of instructions that manipulate binary data at bit level.
These instructions operate on binary values, typically stored in registers, and allow the
CPU to perform tasks like bitwise, logical operations and data manipulation.
Here are some common logical operations found in an instruction set:
1. Bitwise AND (AND): The AND instruction performs a logical AND operation between
two binary values and stores the result in a destination location. It sets each bit of the
result to 1 only if the corresponding bits of both operands are 1. For Example,
AND R1, R2 performs a bitwise AND operation between the contents of registers
R1 and R2, and stores the result in register R1.
ANA B performs a logical AND operation between the contents of the
accumulator and the contents of the B register.
2. Bitwise OR (OR): The OR instruction performs a logical OR operation between two
binary values and stores the result in a destination location. It sets each bit of the result
to 1 if at least one of the corresponding bits in the operands is 1. For example,
OR R1, R2 performs a bitwise OR operation between the contents of registers
R1 and R2, and stores the result in register R1.
ORA C performs a logical OR operation between the contents of the accumulator
and the contents of the C register.
3. Bitwise XOR (XOR): The XOR instruction performs a logical exclusive OR operation
between two binary values and stores the result in a destination location. It sets each bit
of the result to 1 if the corresponding bits in the operands are different. For example,
XOR R1, R2 performs a bitwise XOR operation between the contents of registers
R1 and R2, and stores the result in register R1.
XRA M performs a logical XOR operation between contents of the accumulator
and the contents of the memory location pointed to by the HL register.
10
4. Bitwise NOT (NOT): The NOT instruction performs a logical negation operation on a
binary value and stores the result in a destination location. It flips each bit of the
operand, turning 1s into 0s and 0s into 1s. For example,
NOT R1 performs a bitwise NOT operation on the content of register R1 and
stores the result in register R1.
In addition to these basic logical operations, some instruction sets may provide additional
instructions for more specialized logical operations, such as shifting and rotating bits,
testing specific bits, or setting or clearing individual bits within a register.
11
6. Exchange (XCHG): This instruction exchanges the content of two registers or a register
and a memory location. It is used for swapping data between two storage locations.
7. Block Transfer: Some instruction sets include specialized instructions for transferring
blocks of data between memory and registers. These instructions allow efficient
movement of large amounts of data by specifying a source address, a destination
address, and a count of bytes or elements to be transferred.
The data transfer instructions move data b/w registers or b/w memory and registers.
Opcode Operand Data transfer instructions Explanation Example
MOV Rd, Rs Move Rd=Rs MOV A, B
MOV Rd, M Move Rd=Mc MOV A, 2050
MOV M, Rs Move M=Rs MOV 2050, A
MVI Rd, 8-bit Move Immediate Rd=8-bit data MVI A, 50
data
MVI M, 8-bit data Move Immediate M=8-bit data MVI 2050, 50
LDA 16-bit Load Accumulator Directly A=contents at LDA 2050
address from Memory address
STA 16-bit Store Accumulator Directly Contents at STA 2050
address in Memory address=A
14
15
16
FLOATING-POINT ADDITION ALGORITHM:
1. Align the exponents by adjusting the significands and exponents.
2. Add the significands based on the sign of the numbers.
3. Normalize the result by adjusting the exponent and significand if necessary.
4. Apply rounding rules to obtain the final result.
Example: Let's add two floating-point numbers: 1.234 x 10^3 and 5.678 x 10^2.
Step 1: Align the exponents,
We need to adjust the second number to have the same exponent as the first number.
1.234 x 10^3 + 0.5678 x 10^3
Step 2: Add the significands 1.234 + 0.5678 = 1.8018
Step 3: Normalize the result by adjusting the exponent and significand. 1.8018 x 10^3
Step 4: Apply rounding rules to obtain the final result.
For above example, rounding to two decimal places: 1.80 x 10^3
Therefore, the sum of 1.234 x 10^3 and 5.678 x 10^2 is approximately 1.80 x 10^3.
17
FLOATING-POINT MULTIPLICATION ALGORITHM:
1. Multiply the significands.
2. Add the exponents.
3. Normalize the result by adjusting the exponent and significand if necessary.
4. Apply rounding rules to obtain the final result.
Example: Let's multiply two floating-point numbers: 2.345 x 10^4 and 1.234 x 10^3.
Step 1: Multiply the significands 2.345 x 1.234 = 2.88863
Step 2: Add the exponents. 4+3=7
Step 3: Normalize the result by adjusting the exponent and significand. 2.88863 x 10^7
Step 4: Apply rounding rules to obtain the final result.
For above example, rounding to four decimal places: 2.8886 x 10^7
Therefore, the product of 2.345 x 10^4 and 1.234 x 10^3 is approximately 2.8886 x 10^7.
18