Skip to content

Commit

Permalink
Add ECAL instruction (#523)
Browse files Browse the repository at this point in the history
Closes #521
  • Loading branch information
Dentosal authored Oct 12, 2023
1 parent fffabba commit 822f13a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/fuel-vm/instruction-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
- [K256: keccak-256](#k256-keccak-256)
- [S256: SHA-2-256](#s256-sha-2-256)
- [Other Instructions](#other-instructions)
- [ECAL: Call external function](#ecal-call-external-function)
- [FLAG: Set flags](#flag-set-flags)
- [GM: Get metadata](#gm-get-metadata)
- [GTF: Get transaction fields](#gtf-get-transaction-fields)
Expand Down Expand Up @@ -2352,6 +2353,22 @@ Panic if:

All these instructions advance the program counter `$pc` by `4` after performing their operation.

### ECAL: Call external function

| | |
|-------------|--------------------------------------------------------------------------|
| Description | Call an external function that has full access to the VM state. |
| Operation | `external(&mut vm, $rA, $rB, $rC, $rD)` |
| Syntax | `ecal $rA $rB $rC $rD` |
| Encoding | `0x00 rA rB rC rD` |
| Notes | Does nothing by default, but the VM user can define this to do anything. |

This function provides an escape hatch from the VM, similar to `ecall` instruction of RISC-V. The suggested convention is to use `$rA` for "system call number", i.e. identifying the procedure to call, but all arguments can be used freely. The operation can modify the VM state freely, including writing to registers and memory. Again, the suggested convention is to use `$rA` for the return value and `$err` for any possible errors. However, these conventions can be ignored when necessary.

Panic if:

- The external function panics.

### FLAG: Set flags

| | |
Expand Down

0 comments on commit 822f13a

Please sign in to comment.