From 3e8c8af804be41ad6d19da3077ebfdd2ed0b4e77 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Fri, 14 Mar 2025 12:12:58 +0200 Subject: [PATCH 1/2] Add JAL instruction --- src/fuel-vm/instruction-set.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md index ba796311..240a5a21 100644 --- a/src/fuel-vm/instruction-set.md +++ b/src/fuel-vm/instruction-set.md @@ -61,6 +61,7 @@ - [`JNZF`: Jump if not zero relative forwards](#jnzf-jump-if-not-zero-relative-forwards) - [`JNEB`: Jump if not equal relative backwards](#jneb-jump-if-not-equal-relative-backwards) - [`JNEF`: Jump if not equal relative forwards](#jnef-jump-if-not-equal-relative-forwards) + - [`JAL`: Jump and link](#jal-jump-and-link) - [`RET`: Return from context](#ret-return-from-context) - [Memory Instructions](#memory-instructions) - [`ALOC`: Allocate memory](#aloc-allocate-memory) @@ -1297,6 +1298,21 @@ Panic if: - `$pc + ($rC + imm + 1) * 4 > VM_MAX_RAM - 1` +### `JAL`: Jump and link + +| | | +|-------------|-------------------------------------------------------------------------------------------| +| Description | Set `$rA` to address of the next instruction. Jump to instruction at address `$rB + imm`. | +| Operation | `if $rA is not $zero { $rA = $pc + 4 }`
`$pc = $rB + imm + 4` | +| Syntax | `jal $rA $rB imm` | +| Encoding | `0x00 rA rB i i` | +| Notes | If `$rA` is `$zero`, the return address discarded. | + +Panic if: + +- `$rA` is a reserved register other than `$zero` +- `$rB + imm * 4 >= VM_MAX_RAM` + ### `RET`: Return from context | | | From 8d726c8295200202d667b66cd03237e44332e8f2 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 27 Mar 2025 21:01:03 +0200 Subject: [PATCH 2/2] Correctly use imm * 4 in all fields --- src/fuel-vm/instruction-set.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md index 6208d9ac..4a839b18 100644 --- a/src/fuel-vm/instruction-set.md +++ b/src/fuel-vm/instruction-set.md @@ -1300,13 +1300,13 @@ Panic if: ### `JAL`: Jump and link -| | | -|-------------|-------------------------------------------------------------------------------------------| -| Description | Set `$rA` to address of the next instruction. Jump to instruction at address `$rB + imm`. | -| Operation | `if $rA is not $zero { $rA = $pc + 4 }`
`$pc = $rB + imm + 4` | -| Syntax | `jal $rA $rB imm` | -| Encoding | `0x00 rA rB i i` | -| Notes | If `$rA` is `$zero`, the return address discarded. | +| | | +|-------------|-----------------------------------------------------------------------------------------------| +| Description | Set `$rA` to address of the next instruction. Jump to instruction at address `$rB + imm * 4`. | +| Operation | `if $rA is not $zero { $rA = $pc + 4 }`
`$pc = $rB + imm * 4` | +| Syntax | `jal $rA $rB imm` | +| Encoding | `0x00 rA rB i i` | +| Notes | If `$rA` is `$zero`, the return address discarded. | Panic if: