Files
powdr/test_data/std/memory_test.asm
Leandro Pacheco abbe26618f Instructions with link statements (#1439)
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.
2024-06-18 17:31:38 +00:00

62 lines
1.2 KiB
Rust

use std::machines::memory::Memory;
machine Main with degree: 65536 {
reg pc[@pc];
reg X[<=];
reg Y[<=];
reg A;
col fixed STEP(i) { i };
Memory memory;
instr mload X -> Y link ~> Y = memory.mload(X, STEP);
instr mstore X, Y -> link ~> memory.mstore(X, STEP, Y);
instr assert_eq X, Y {
X = Y
}
function main {
// Store 4
mstore 100, 4;
// Read uninitialized memory
A <== mload(104);
assert_eq A, 0;
// Read previously stored value
A <== mload(100);
assert_eq A, 4;
// Update previously stored value
mstore 100, 7;
mstore 100, 8;
// Read updated values (twice)
A <== mload(100);
assert_eq A, 8;
A <== mload(100);
assert_eq A, 8;
// Write to previously uninitialized memory cell
mstore 104, 1234;
A <== mload(104);
assert_eq A, 1234;
// Write very big field element
mstore 200, -1;
A <== mload(200);
assert_eq A, -1;
// Store at maximal address
mstore 0xfffffffc, 1;
A <== mload(0xfffffffc);
assert_eq A, 1;
return;
}
}