Files
powdr/test_data/std/binary_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

68 lines
1.7 KiB
Rust

use std::machines::binary::Binary;
machine Main with degree: 262144 {
reg pc[@pc];
reg X0[<=];
reg X1[<=];
reg X2[<=];
reg A;
Binary binary;
instr and X0, X1 -> X2 link ~> X2 = binary.and(X0, X1);
instr or X0, X1 -> X2 link ~> X2 = binary.or(X0, X1);
instr xor X0, X1 -> X2 link ~> X2 = binary.xor(X0, X1);
instr assert_eq X0, X1 {
X0 = X1
}
function main {
// AND
A <== and(0, 0);
assert_eq A, 0;
A <== and(0xffffffff, 0xffffffff);
assert_eq A, 0xffffffff;
A <== and(0xffffffff, 0xabcdef01);
assert_eq A, 0xabcdef01;
A <== and(0xabcdef01, 0xffffffff);
assert_eq A, 0xabcdef01;
A <== and(0, 0xabcdef01);
assert_eq A, 0;
A <== and(0xabcdef01, 0);
assert_eq A, 0;
// OR
A <== or(0, 0);
assert_eq A, 0;
A <== or(0xffffffff, 0xffffffff);
assert_eq A, 0xffffffff;
A <== or(0xffffffff, 0xabcdef01);
assert_eq A, 0xffffffff;
A <== or(0xabcdef01, 0xffffffff);
assert_eq A, 0xffffffff;
A <== or(0, 0xabcdef01);
assert_eq A, 0xabcdef01;
A <== or(0xabcdef01, 0);
assert_eq A, 0xabcdef01;
// XOR
A <== xor(0, 0);
assert_eq A, 0;
A <== xor(0xffffffff, 0xffffffff);
assert_eq A, 0;
A <== xor(0xffffffff, 0xabcdef01);
assert_eq A, 0x543210fe;
A <== xor(0xabcdef01, 0xffffffff);
assert_eq A, 0x543210fe;
A <== xor(0, 0xabcdef01);
assert_eq A, 0xabcdef01;
A <== xor(0xabcdef01, 0);
assert_eq A, 0xabcdef01;
return;
}
}