Update README.md
This commit is contained in:
@@ -37,13 +37,29 @@ PRINT "Returned value in R0 was 42"
|
|||||||
|
|
||||||
## What Does This Thumb-2 Machine Code Do?
|
## 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.
|
### `CSUB simple`
|
||||||
* The **second 32-bit word** (`20420047`) encodes **two Thumb instructions**:
|
- 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),
|
### `00000000`
|
||||||
* `bx lr` (branch to link register, i.e., return).
|
- The entry point offset for the CSUB.
|
||||||
* When `test()` is called, it runs these two instructions: loads 42 into R0 (commonly used to return values) and then returns.
|
- A value of `0` indicates execution starts immediately at the next word.
|
||||||
* The BASIC program then continues and prints `Returned value in R0 was 42`.
|
- 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.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user