Using different addressing modes, programmers can choose to reference data differently, as required by the program.
Most assembly instructions that require operands follow this syntax, where inst
is the instruction name, dest
denotes the destination, and src
denotes the source:
inst dest src
However, the operand may reside in memory, a register, or may be a constant. Depending on the type of operand an instruction is operating on, addressing in assembly language can be performed in three modes, as shown in the table below:
Mode | Operand Description |
Register Addressing | Stored in a register. |
Memory Addressing | Resides in memory |
Immediate Addressing* | Is a constant or expression |
The following mov
instruction makes uses of register addressing to move the data referred to by esp
into ecx
:
mov ecx, esp
The addressing mode used here is register addressing as the destination operand is a register.
Another example of register addressing would be the inc
instruction, which increments the value of a specified register.
inc eax
In memory addressing, the second operand is a memory location and is usually represented by a variable name. Subsequently, this addressing mode requires access to the data
segment of the program. Here is an example of a mov
instruction that copies data items from the variable bill
stored in the data segment to the register eax
.
mov eax, bill
In immediate addressing, the second operand of the instruction is a constant. The first operand may reside in a register or the memory segment.
The following snippet of code demonstrates how immediate addressing may be used to change the value of a register and a memory location:
mov eax 37
add num 37
The value of the register eax
and the memory location pointed to by the variable num
(its previous value was 0) has been set to 37
, which is %
in ASCII.
Free Resources