can run fibonacci sequence, nqueen

This commit is contained in:
yoyo
2024-11-04 02:11:36 +09:00
parent 1bff7d30e7
commit 00f87d4e55
17 changed files with 113 additions and 85 deletions

View File

@@ -170,6 +170,18 @@ D91(void)
R.m = R.FP+R.PC->reg;
}
static void
D92(void)
{
R.s = (u8*)&R.PC->s.imm;
R.d = (u8*)&R.PC->d.imm;
R.m = R.FP+R.PC->reg;
}
static void
D93(void)
{
R.s = (u8*)&R.PC->s.imm;
}
static void
D95(void)
{
R.s = (u8*)&R.PC->s.imm;
@@ -216,6 +228,8 @@ void (*dec[])(void) =
[0x8A] = D8A,
[0x8D] = D8D,
[0x91] = D91,
[0x92] = D92,
[0x93] = D93,
[0x95] = D95,
[0xA9] = DA9,
[0xAD] = DAD,

12
vm/vm.c
View File

@@ -1,6 +1,6 @@
#include "vm.h"
static u8 end[1];
static u8 end[1024];
u32 ninst;
Inst *inst;
REG R;
@@ -47,10 +47,10 @@ rd2(FILE *f)
assert(fread(&v, 1, 2, f) == 2);
return v;
}
u32
WORD
rd4(FILE *f)
{
u32 v = 0;
i32 v = 0;
assert(fread(&v, 1, 4, f) == 4);
return v;
}
@@ -86,6 +86,7 @@ OP(bneqw) {if(W(s) != W(m)) JMP(d);}
OP(ltw) {W(d) = (W(s) < W(m));}
OP(leqw) {W(d) = (W(s) <= W(m));}
OP(eqw) {W(d) = (W(s) == W(m));}
OP(neqw) {W(d) = (W(s) != W(m));}
OP(frame){
Stack *s;
Frame *f;
@@ -116,6 +117,7 @@ OP(ret) {
R.FP = f->fp;
if(R.FP == NULL){
printf("result %ld\n", W(d));
WORD *p = end;
exit(0);
}
R.SP = (u8*)f;
@@ -150,7 +152,8 @@ OP(slice){
if(s2 == -1)
s2 = a->len;
assert(s1 >= 0 && s1 < a->len);
assert(s2 >= 0 && s2 < a->len);
assert(s2 >= 0 && s2 <= a->len);
assert(s1 < s2);
Array d = *a;
d.len = s2 - s1;
d.cap = s2 - s1;
@@ -175,6 +178,7 @@ static void (*optab[])(void) = {
[IBEQW] = beqw,
[IBNEQW] = bneqw,
[IEQW] = eqw,
[INEQW] = neqw,
[ILEQW] = leqw,
[ILTW] = ltw,
};

View File

@@ -61,7 +61,7 @@ struct REG
u8 *TS;
u8 *EX;
void *s, *d, *m;
int t, dt ,mt;
WORD t, dt ,mt;
};
struct Array