Immediate Addressing Mode

Immediate Addressing Mode

Immediate addressing mode allows programmers to directly specify constant values within instructions. It involves embedding the actual data directly into the instruction itself.

Example

Intel Syntax:

In Intel syntax, immediate operands are specified directly following the instruction mnemonic, separated by a comma. Immediate values can be represented in various formats, such as decimal, hexadecimal, or binary.

; Intel Syntax
mov eax, 10         ; Load the immediate value 10 into the eax register
add ebx, 0x20       ; Add the immediate hexadecimal value 0x20 to the ebx register
cmp ecx, 100        ; Compare the ecx register with the immediate value 100

In Intel syntax, immediate values are typically represented without any prefix for decimal values, with 0x prefix for hexadecimal values.

AT&T Syntax:

In contrast, AT&T syntax places the immediate operand after the instruction mnemonic, prefixed with a dollar sign ($).

# AT&T Syntax
mov $10, %eax       # Load the immediate value 10 into the eax register
add $0x20, %ebx     # Add the immediate hexadecimal value 0x20 to the ebx register
cmp $100, %ecx      # Compare the ecx register with the immediate value 100

In AT&T syntax, immediate values are often represented with a dollar sign prefix, followed by the value itself. Additionally, registers are prefixed with a percent sign (%) to distinguish them from immediate values.