The immediate addressing mode is used in many computer architectures for several purposes, such as:
-
Initialization of variables: The immediate addressing mode is often used to initialize variables with a constant value. For example, if a program needs to set a register to a specific value, it can use the immediate addressing mode to load that value directly into the register.
-
Arithmetic operations: Immediate addressing mode is also used in arithmetic operations where the value of the operand needs to be added, subtracted, multiplied or divided with another operand. For example, if a program needs to add two values together, it can load the first value using the immediate addressing mode and add the second value from memory.
-
Conditional branching: Immediate addressing mode can also be used in conditional branching instructions, where the immediate value is compared to the value in a register. If the values are equal, the program branches to a specific address. This is often used in loops and decision-making structures.
-
Input/Output operations: Immediate addressing mode can also be used in input/output operations. For example, if a program needs to output a specific value to a device, it can use the immediate addressing mode to load the value into a register and then use an output instruction to send the value to the device.
Example 1: Initialization of variables:
MOV AX, 1234h ; Load the immediate value 1234h into the AX register
Example 2: Arithmetic operations :
MOV AX, 10 ; Load the immediate value 10 into the AX register
ADD AX, 20 ; Add the immediate value 20 to the contents of the AX register
Example 3: Conditional branching :
MOV AX, 5 ; Load the immediate value 5 into the AX register
CMP AX, 5 ; Compare the contents of the AX register to the immediate value 5
JE Label1 ; If the values are equal, jump to Label1.