update 3
This commit is contained in:
@@ -57,3 +57,42 @@ Arguments `g` and `h`, which are 64-bit values, have no registers left and
|
|||||||
are pushed onto the stack instead. `RS` points to 6, reflecting the 4
|
are pushed onto the stack instead. `RS` points to 6, reflecting the 4
|
||||||
caller-saved entries plus 2 stack parameters. After `undo_function_call`,
|
caller-saved entries plus 2 stack parameters. After `undo_function_call`,
|
||||||
all stack entries are cleaned and the result `99` is collected from `RA`.
|
all stack entries are cleaned and the result `99` is collected from `RA`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## TEST 3: Boolean arguments
|
||||||
|
|
||||||
|
**Function signature:** `ok = func(flag1, flag2, flag3, x)`
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
```
|
||||||
|
|
||||||
|
===== TEST 3: Boolean arguments =====
|
||||||
|
=== State after do_function_call ===
|
||||||
|
Registers used: ['RA', 'RB']
|
||||||
|
Stack: [{'type': 'caller_saved', 'reg': 'R0', 'value': 0}, {'type': 'caller_saved', 'reg': 'R1', 'value': 0}, {'type': 'caller_saved', 'reg': 'R2', 'value': 0}, {'type': 'caller_saved', 'reg': 'R3', 'value': 0}]
|
||||||
|
...
|
||||||
|
=== State after undo_function_call ===
|
||||||
|
Clean stack: []
|
||||||
|
RS: 0
|
||||||
|
Collected result: {'ok': {'type': 'result', 'value': True}}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Explanation:**
|
||||||
|
Booleans (1-bit values) are not placed individually into registers.
|
||||||
|
Instead they are accumulated into a queue and packed together before
|
||||||
|
occupying a single register. The 3 boolean flags (flag1, flag2, flag3)
|
||||||
|
are packed together and placed in `RB` as a `bool_pack_padded` entry.
|
||||||
|
The regular argument `x` (8 bits) is placed in `RA` as normal.
|
||||||
|
No arguments overflow to the stack. After `undo_function_call`, the result
|
||||||
|
`True` is successfully collected from `RA`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## General observations
|
||||||
|
|
||||||
|
- The stack always starts and ends with the same state, proving the
|
||||||
|
algorithm correctly preserves the machine's previous context.
|
||||||
|
- Caller-saved registers (R0-R3) are always pushed before the call
|
||||||
|
and restored after, regardless of the number of arguments.
|
||||||
|
- `RS` accurately tracks the stack size at every step.
|
||||||
Reference in New Issue
Block a user