mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-04-20 03:03:25 -04:00
Allow VM instructions to use the `link` notation, unifying the way machines are linked from VMs and block machines. Previous syntax for "external instructions" not allowed anymore, and should use the new `link` syntax.
39 lines
785 B
Rust
39 lines
785 B
Rust
use std::machines::write_once_memory::WriteOnceMemory;
|
|
|
|
machine Main with degree: 256 {
|
|
WriteOnceMemory memory;
|
|
|
|
reg pc[@pc];
|
|
reg X[<=];
|
|
reg Y[<=];
|
|
reg A;
|
|
|
|
instr mload X -> Y link => memory.access(X, Y);
|
|
instr mstore X, Y -> link => memory.access(X, Y);
|
|
|
|
instr assert_eq X, Y { X = Y }
|
|
|
|
function main {
|
|
// Minimal address: 0
|
|
mstore 0, 1234;
|
|
A <== mload(0);
|
|
assert_eq A, 1234;
|
|
|
|
// Maximal address: N - 1
|
|
mstore 255, 1234;
|
|
A <== mload(255);
|
|
assert_eq A, 1234;
|
|
|
|
// Maximal value: Any field element
|
|
mstore 17, -1;
|
|
A <== mload(17);
|
|
assert_eq A, -1;
|
|
|
|
// Read same value again
|
|
A <== mload(17);
|
|
assert_eq A, -1;
|
|
|
|
return;
|
|
}
|
|
}
|