(Part 2)
Memory Access
To access memory we can use these four registers: BX, SI, DI, BP.
Combining these registers inside [ ] symbols, we can get different
memory locations. These combinations are supported (addressing
modes):
[BX + SI]
[BX + DI]
[BP + SI]
[BP + DI]
[SI]
[DI]
d16 (variable offset only)
[BX]
[BX + SI] + d8
[BX + DI] + d8
[BP + SI] + d8
[BP + DI] + d8
[SI] + d8
[DI] + d8
[BP] + d8
[BX] + d8
[BX + SI] + d16
[BX + DI] + d16
[BP + SI] + d16
[BP + DI] + d16
[SI] + d16
[DI] + d16
[BP] + d16
[BX] + d16
d8 - stays for 8 bit displacement.
d16 - stays for 16 bit displacement.
Displacement can be a immediate value or offset of a variable, or
even both. It's up to compiler to calculate a single immediate
value.
Displacement can be inside or outside of [ ] symbols, compiler
generates the same machine code for both ways.
Displacement is a signed value, so it can be both positive or
negative.
Generally the compiler takes care about difference between d8 and
d16, and generates the required machine code.
For example, let's assume that DS = 100, BX = 30, SI = 70.
The following addressing mode: [BX + SI] + 25
is calculated by processor to this physical address: 100 * 16 + 30 + 70
+ 25 = 1725.
By default DS segment register is used for all modes except those
with BP register, for these SS segment register is used. There is an easy
way to remember all those possible combinations using this chart: