Continuous memory: Exercise I

We need to: “Add one instruction at the end of the function (just before ret ) so that there won’t be a memory gap”. Here is the code:

func main() {
    [ap] = 100;
    [ap + 2] = 200;
    ret;
}
13 Likes

When I debug the above function, this is what I get in memory:

1 0x400680017fff8000
2 100
3 0x400680017fff8002
4 200
5 0x208b7fff7fff7ffe
6 11
7 11
8 100
10 200

Values 100 and 200 are stored at memory locations 0x400680017fff8000 and 0x400680017fff8002 respectively. To fill the gap we need to store the new value at memory location 0x400680017fff8001. This could be done as follows:

func main() {
    [ap] = 100;
    [ap + 2] = 200;
    [ap + 1] = 67; // the order of access doesn’t matter
    ret;
}
13 Likes