mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-04-20 03:03:25 -04:00
With the recent changes by @pacheco, we can extract our [memory
machine](https://github.com/powdr-labs/powdr/blob/main/riscv/src/compiler.rs#L687-L841)
as a separate machine and add it to the standard library.
The result should be the same as calling the function linked above with
`with_bootloader=false`, except that the memory alignment stuff is not
inlined. For this reason, the machine is not yet used by the RISC-V
machine, but it could be after #1077 is implemented.
[This](eb320dca0c) shows the diff from
what we have in `compiler.rs`.
<!--
Please follow this protocol when creating or reviewing PRs in this
repository:
- Leave the PR as draft until review is required.
- When reviewing a PR, every reviewer should assign themselves as soon
as they
start, so that other reviewers know the PR is covered. You should not be
discouraged from reviewing a PR with assignees, but you will know it is
not
strictly needed.
- Unless the PR is very small, help the reviewers by not making forced
pushes, so
that GitHub properly tracks what has been changed since the last review;
use
"merge" instead of "rebase". It can be squashed after approval.
- Once the comments have been addressed, explicitly let the reviewer
know the PR
is ready again.
-->
63 lines
1.2 KiB
NASM
63 lines
1.2 KiB
NASM
use std::memory::Memory;
|
|
|
|
machine Main {
|
|
reg pc[@pc];
|
|
reg X[<=];
|
|
reg Y[<=];
|
|
reg A;
|
|
|
|
degree 65536;
|
|
|
|
col fixed STEP(i) { i };
|
|
Memory memory;
|
|
|
|
instr mload X -> Y ~ memory.mload X, STEP -> Y;
|
|
instr mstore X, Y -> ~ 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;
|
|
}
|
|
} |