liveBook · Manning

Return opcode

As explained in Rust in Action: Systems programming concepts and techniques

The RETURN opcode restores CPU execution to the address saved by a preceding function call.

The RETURN opcode, written 0x00EE, ends a function by removing the most recent saved address from the stack and restoring CPU execution there. section 5.7.4

Returning from add_twice

The function add_twice executes 0x8014 twice, then 0x00EE. RETURN transfers control back through the address saved by CALL.

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Implements stack popping and execution restoration, while stopping short of language-level function support.
Examples
Uses the add_twice function, two addition opcodes, the 0x00EE encoding, and illustrated control flow.
What it assumes
Assumes opcode execution and CALL behavior, while introducing the stack as address storage for function control flow.
What you can do after
Build a Rust emulator method that safely returns from functions and detects stack underflow.
How it connects
Connects function calls, the CALL opcode, the stack, the stack pointer, and CPU instruction execution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.