Update README.md

This commit is contained in:
Jason
2025-12-08 20:34:12 +11:00
committed by GitHub
parent 3bf897d88e
commit cc3982442e
+22 -6
View File
@@ -37,13 +37,29 @@ PRINT "Returned value in R0 was 42"
## What Does This Thumb-2 Machine Code Do?
* The **first 32-bit word** (`00000000`) is the **entry point offset**, meaning execution starts at the first instruction.
* The **second 32-bit word** (`20420047`) encodes **two Thumb instructions**:
### `CSUB simple`
- Starts the definition of a machine-code subroutine named `simple`.
- Tells the BASIC runtime that the following hex words are compiled machine code to execute when `simple()` is called.
* `movs r0, #42` (load immediate value 42 into register R0),
* `bx lr` (branch to link register, i.e., return).
* When `test()` is called, it runs these two instructions: loads 42 into R0 (commonly used to return values) and then returns.
* The BASIC program then continues and prints `Returned value in R0 was 42`.
### `00000000`
- The entry point offset for the CSUB.
- A value of `0` indicates execution starts immediately at the next word.
- This word is metadata only; it is **not executed** as machine code.
### `00004770`
- Encodes the Thumb instruction `BX LR` (Branch to Link Register).
- This instruction **returns immediately** from the subroutine to BASIC.
### `END CSUB`
- Marks the end of the CSUB block.
- Signals that the machine code definition is complete, and BASIC execution continues normally.
### `simple()`
- Calls the subroutine `simple`.
- Execution jumps to the CSUB, reads the entry point offset, executes the `BX LR` instruction, and immediately returns.
### `PRINT " Returned successfully"`
- Prints a message to the BASIC console to indicate the subroutine returned successfully.
---