Creating Our Own Fibers 104 In later examples, we will use all the registers marked as callee saved in the specification document I linked to. These are the registers described in the System V x86-64 ABI that we'll need to save our context, but right now, we only need one register to make the CPU jump over to our stack. Note that this needs to be #[repr(C)] because of how we access the data in our assembly. Rust doesn't have a stable language ABI, so there is no way for us to be sure that this will be represented in memory with rsp as the first 8 bytes. C has a stable language ABI and that's exactly what this attribute tells the compiler to use. Granted, our struct only has one field right now, but we will add more later. For this very simple example, we will define a function that just prints out a message and then loops forever: fn hello()-> ! { println!("I LOVE WAKING UP ON A NEW STACK!"); loop {} } Next up is our inline assembly, where we switch over to our own stack: unsafe fn gt_switch(new: *const Thread Context) { asm!( "mov rsp, [{0} + 0x00]", "ret", in(reg) new, ); } At first glance, you might think that there is nothing special about this piece of code, but let's stop and consider what happens here for a moment. If we refer back to Figure 5. 1, we'll see that rsp is the register that stores the stack pointer that the CPU uses to figure out the current location on the stack. Now, what we actually want to do if we want the CPU to swap to a different stack is to set the register for the stack pointer ( rsp ) to the top of our new stack and set the instruction pointer ( rip ) on the CPU to point to the address hello. The instruction pointer, or program counter as it's sometimes called on different architectures, points to the next instruction to run. If we can manipulate it directly, the CPU would fetch the instruction pointed to by the rip register and execute the first instruction we wrote in our hello function. The CPU will then push/pop data on the new stack using the address pointed to by the stack pointer and simply leave our old stack as it was. Now, this is where it gets a little difficult. On the x86-64 instruction set, there is no way for us to manipulate rip directly, so we have to use a little trick.