diff options
| author | 2025-08-12 20:27:34 +0330 | |
|---|---|---|
| committer | 2025-08-12 20:27:34 +0330 | |
| commit | 15914727d83a6f46ad724e126179713d935e5e6f (patch) | |
| tree | 2f601872b7575e4f3c0ca8c366fb2a1e1ea1b4fb /pu2/pu2test.c | |
| parent | ir2 initial release! (diff) | |
ir2 prototype! includes strings and DATA segment and other stuffs :3
Diffstat (limited to 'pu2/pu2test.c')
| -rw-r--r-- | pu2/pu2test.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/pu2/pu2test.c b/pu2/pu2test.c index 93d76aa..8b94cad 100644 --- a/pu2/pu2test.c +++ b/pu2/pu2test.c @@ -1,5 +1,4 @@ -#define __WRAPPER -#include "pu2.c" +#include "pu2.out.c" #include <stdio.h> #include <string.h> @@ -13,11 +12,15 @@ static int total_tests = 0; static int passed_tests = 0; +#define static_len(G) (sizeof(G) / sizeof((G)[ 0 ])) + /* helper: load program at pc and set PC (m[7]) */ void load_prog(int pc, int *prog, int len) { int i; + a = b = 0; + u = 1; /* clear memory (keeps tests isolated) */ - for (i = 0; i < S; ++i) m[ i ] = 0; + for (i = 0; i < static_len(m); ++i) m[ i ] = 0; for (i = 0; i < len; ++i) m[ pc + i ] = prog[ i ]; m[ 7 ] = pc; } @@ -33,7 +36,7 @@ void expect_int(const char *name, int got, int want) { } } -unsigned char outbuf[ 512 ]; +int outbuf[ 512 ]; void zero_Y(void) { int ii; @@ -42,7 +45,7 @@ void zero_Y(void) { void set_outbuf(void) { memset(outbuf, 0, sizeof outbuf); - O = (char *) outbuf; + O = outbuf; zero_Y(); } @@ -165,7 +168,7 @@ int main(void) { /* Assembler (as2) tests: use outbuf */ { - unsigned char *o; + int *o; set_outbuf(); as2("hlt"); @@ -188,19 +191,19 @@ int main(void) { expect_int("sub:imm", o[ 3 ], 0); set_outbuf(); - as2("(0 hlt) @0"); + as2("{0 hlt} @0"); o = outbuf; expect_int("macro-hlt:opcode", o[ 0 ], 0); expect_int("macro-hlt:imm", o[ 1 ], 0); set_outbuf(); - as2("(0 imm 7) @0"); + as2("{0 imm 7} @0"); o = outbuf; expect_int("macro-imm:opcode", o[ 0 ], 1); expect_int("macro-imm:imm", o[ 1 ], 7); set_outbuf(); - as2("(0 imm 3 add) @0"); + as2("{0 imm 3 add} @0"); o = outbuf; expect_int("macro-mix:imm-op", o[ 0 ], 1); expect_int("macro-mix:imm-val", o[ 1 ], 3); |
