Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Add Opcode::BAL
Browse files Browse the repository at this point in the history
  • Loading branch information
vlopes11 committed Nov 30, 2021
1 parent 9b36447 commit ebc2f1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,22 @@ pub enum Opcode {
/// check](./main.md#ownership)
SW(RegisterId, RegisterId, Immediate12),

/// Set `$rA` to the balance of color at `$rB` for contract with ID at
/// `$rC`. Where helper
/// `balance(color: byte[32], contract_id: byte[32]) -> uint64`
/// returns the current balance of `color` of contract with ID
/// `contract_id`.
///
/// | Operation | ```$rA = balance(MEM[$rB, 32], MEM[$rC, 32]);``` |
/// | Syntax | `bal $rA, $rB, $rC` |
/// | Encoding | `0x00 rA rB rC -` |
///
/// #### Panics
/// - `$rA` is a [reserved register](./main.md#semantics)
/// - `$rB + 32` overflows
/// - `$rB + 32 > VM_MAX_RAM`
BAL(RegisterId, RegisterId, RegisterId),

/// Get block header hash.
///
/// | Operation | ```MEM[$rA, 32] = blockhash($rB);``` |
Expand Down Expand Up @@ -1334,6 +1350,7 @@ impl Opcode {
OpcodeRepr::MEQ => Opcode::MEQ(ra, rb, rc, rd),
OpcodeRepr::SB => Opcode::SB(ra, rb, imm12),
OpcodeRepr::SW => Opcode::SW(ra, rb, imm12),
OpcodeRepr::BAL => Opcode::BAL(ra, rb, rc),
OpcodeRepr::BHSH => Opcode::BHSH(ra, rb),
OpcodeRepr::BHEI => Opcode::BHEI(ra),
OpcodeRepr::BURN => Opcode::BURN(ra),
Expand Down Expand Up @@ -1440,6 +1457,7 @@ impl Opcode {
Self::MEQ(ra, rb, rc, rd) => [Some(*ra), Some(*rb), Some(*rc), Some(*rd)],
Self::SB(ra, rb, _) => [Some(*ra), Some(*rb), None, None],
Self::SW(ra, rb, _) => [Some(*ra), Some(*rb), None, None],
Self::BAL(ra, rb, rc) => [Some(*ra), Some(*rb), Some(*rc), None],
Self::BHSH(ra, rb) => [Some(*ra), Some(*rb), None, None],
Self::BHEI(ra) => [Some(*ra), None, None, None],
Self::BURN(ra) => [Some(*ra), None, None, None],
Expand Down Expand Up @@ -1527,6 +1545,7 @@ impl Opcode {
| Self::MCL(_, _)
| Self::MCP(_, _, _)
| Self::MEQ(_, _, _, _)
| Self::BAL(_, _, _)
| Self::BHSH(_, _)
| Self::BHEI(_)
| Self::BURN(_)
Expand Down Expand Up @@ -1876,6 +1895,12 @@ impl From<Opcode> for u32 {
| ((rb as u32) << 12)
| (imm12 as u32)
}
Opcode::BAL(ra, rb, rc) => {
((OpcodeRepr::BAL as u32) << 24)
| ((ra as u32) << 18)
| ((rb as u32) << 12)
| ((rc as u32) << 6)
}
Opcode::BHSH(ra, rb) => {
((OpcodeRepr::BHSH as u32) << 24) | ((ra as u32) << 18) | ((rb as u32) << 12)
}
Expand Down
4 changes: 2 additions & 2 deletions src/opcode/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ pub enum OpcodeRepr {
NOOP = 0x47,
/// FLAG
FLAG = 0x48,
/// RESERV49
RESERV49 = 0x49,
/// BAL
BAL = 0x49,
/// RESERV4A
RESERV4A = 0x4a,
/// RESERV4B
Expand Down
1 change: 1 addition & 0 deletions tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn opcode() {
Opcode::MEQ(r, r, r, r),
Opcode::SB(r, r, imm12),
Opcode::SW(r, r, imm12),
Opcode::BAL(r, r, r),
Opcode::BHSH(r, r),
Opcode::BHEI(r),
Opcode::BURN(r),
Expand Down

0 comments on commit ebc2f1b

Please sign in to comment.