An Example

This lesson illustrates the concept of address translation with the help of an example.

To understand better what we need to do to implement address translation, and why we need such a mechanism, let’s look at a simple example. Imagine there is a process whose address space is as indicated in the figure below:

Looking at the disassembled code

What we are going to examine here is a short code sequence that loads a value from memory, increments it by three, and then stores the value back into memory. You can imagine the C-language representation of this code might look like this:

Press + to interact
void func() {
int x = 3000; // thanks, Perry.
x = x+3; //line of code we are interested in ...

The compiler turns this line of code into assembly, which might look something like this (in x86 assembly). You may use objdump on Linux or otool on a Mac to disassemble it:

Press + to interact
128: movl 0x0(%ebx), %eax ;load 0+ebx into eax
132: addl $0x03, %eax ;add 3 to eax register
135: movl %eax, 0x0(%ebx) ;store eax back to mem

This code snippet is relatively ...