Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created March 7, 2019 16:52
Embed
What would you like to do?

CAVEATS:

We are assuming 0x000 is a valid address.

Pointers are 8 bytes, this is a 64 bit machine.

I forget which way the stack grows and so I'm doing it upwards, i think it's downwards on x86 but whatever.

Execute:

let mut x = 1;

Memory:

name location type value
x 0x000 i32 1

Execute:

let y = &mut x;

Memory:

name location type value
x 0x000 i32 1
y 0x004 &mut i32 0x000

Execute:

let z = *y;

Memory:

name location type value
x 0x000 i32 1
y 0x004 &mut i32 0x000
z 0x00C i32 1

Execute:

let a = &z;

Memory:

name location type value
x 0x000 i32 1
y 0x004 &mut i32 0x000
z 0x00C i32 1
a 0x00F &i32 0x00C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment