An example we can build upon 103 One more thing to note is that the stack alignment on x86-64 is 16 bytes. Just remember this for later. An example we can build upon This is a short example where we will create our own stack and make our CPU return out of its current execution context and over to the stack we just created. We will build on these concepts in the following chapters. Setting up our project First, let's start a new project by creating a folder named a-stack-swap. Enter the new folder and run the following: cargo init Tip Y ou can also navigate to the folder called ch05/a-stack-swap in the accompanying repository and see the whole example there. In our main. rs, we start by importing the asm! macro: ch05/a-stack-swap/src/main. rs use core::arch::asm; Let's set a small stack size of only 48 bytes here so that we can print the stack and look at it before we switch contexts after we get the first example to work: const SSIZE: isize = 48; Note There seems to be an issue in mac OS using such a small stack. The minimum for this code to run is a stack size of 624 bytes. The code works on the Rust Playground, at https://play. rust-lang. org, if you want to follow this exact example (however, you'll need to wait roughly 30 seconds for it to time out due to our loop in the end). Then let's add a struct that represents our CPU state. We'll only focus on the register that stores the stack pointer for now since that is all we need: #[derive(Debug, Default)] #[repr(C)] struct Thread Context { rsp: u64, }