A computed memory address is just another integer on the operand stack. For a pointer held at fixed address , const p; load obtains the pointed-to address; another load obtains its contents. More generally, any expression that leaves an address on top may be followed by load, or may be retained beneath a computed value for store.
For an array whose base address is and whose element size is address units, the address of entry is , where stores the index. Add zero-address instructions mul and dup, with dup mapping to . A suitable sequence is
const b
const p_i
load
const w
mul
add
dup
load
const 1
add
store
The first six instructions leave the element address . The remaining suffix evolves as
with the final effect
The address is computed once and duplicated, so both accesses refer to the same array element. For unit-sized elements omit const w; mul. If the base address is itself held in a variable, replace const b by the instructions loading that variable's value. No instruction other than const requires an explicit operand.

Articles by others on the same topic (0)

There are currently no matching articles.