Compare commits
No commits in common. "e5f2858a5c80de897e620948c505fe037708ed57" and "70dbd0253bd5aedec6946cee28f5457594fa1610" have entirely different histories.
e5f2858a5c
...
70dbd0253b
@ -5,7 +5,5 @@ set(CMAKE_C_STANDARD 99)
|
|||||||
|
|
||||||
add_compile_options(-g -Wall -pedantic)
|
add_compile_options(-g -Wall -pedantic)
|
||||||
|
|
||||||
include_directories("./bigint/build/include")
|
|
||||||
|
|
||||||
add_executable(ninja njvm.c
|
add_executable(ninja njvm.c
|
||||||
SDA.c)
|
SDA.c)
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -4,7 +4,7 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
# program to Run
|
# program to Run
|
||||||
F = programs/prog1.bin
|
F = prog.bin
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
CFLAGS = -g -Wall -Ibigint/build/include
|
CFLAGS = -g -Wall -Ibigint/build/include
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
37
njvm.c
37
njvm.c
@ -9,7 +9,6 @@
|
|||||||
#include "SDA.c"
|
#include "SDA.c"
|
||||||
#include "debugMenu.c"
|
#include "debugMenu.c"
|
||||||
#include "bigint.h"
|
#include "bigint.h"
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ void execute(struct program program) {
|
|||||||
StackSlot tempSlot;
|
StackSlot tempSlot;
|
||||||
ObjRef tempObj;
|
ObjRef tempObj;
|
||||||
for (i = 0; i < *program.size; ++i) {
|
for (i = 0; i < *program.size; ++i) {
|
||||||
if (debug == 1) debugMenu(fp, stack, &debug);
|
if (debug == 1) debugMenu(fp,stack,&debug);
|
||||||
switch (program.program[i] >> 24) {
|
switch (program.program[i] >> 24) {
|
||||||
case HALT:
|
case HALT:
|
||||||
if (debug == 1) printf("halt\n");
|
if (debug == 1) printf("halt\n");
|
||||||
@ -60,11 +59,8 @@ void execute(struct program program) {
|
|||||||
push(stack, stackSlotWithObjRef(getIntObj(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
push(stack, stackSlotWithObjRef(getIntObj(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||||
break;
|
break;
|
||||||
case ADD:
|
case ADD:
|
||||||
if (debug == 1) printf("add: %i + %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("add: %i + %i\n",peek(stack, 2),peek(stack, 1));
|
||||||
bip.op1 = pop(stack).u.objRef;
|
push(stack, stackSlotWithObjRef(getIntObj(getIntValfromStackSlot(pop(stack)) + getIntValfromStackSlot(pop(stack)))));
|
||||||
bip.op2 = pop(stack).u.objRef;
|
|
||||||
bigAdd();
|
|
||||||
push(stack, stackSlotWithObjRef(bip.res));
|
|
||||||
break;
|
break;
|
||||||
case SUB:
|
case SUB:
|
||||||
if (debug == 1) printf("sub: %i - %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("sub: %i - %i\n", peek(stack, 2), peek(stack, 1));
|
||||||
@ -73,8 +69,7 @@ void execute(struct program program) {
|
|||||||
break;
|
break;
|
||||||
case MUL:
|
case MUL:
|
||||||
if (debug == 1) printf("mul: %i * %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("mul: %i * %i\n", peek(stack, 2), peek(stack, 1));
|
||||||
push(stack, stackSlotWithObjRef(
|
push(stack, stackSlotWithObjRef(getIntObj(getIntValfromStackSlot(pop(stack)) * getIntValfromStackSlot(pop(stack)))));
|
||||||
getIntObj(getIntValfromStackSlot(pop(stack)) * getIntValfromStackSlot(pop(stack)))));
|
|
||||||
break;
|
break;
|
||||||
case DIV:
|
case DIV:
|
||||||
if (debug == 1) printf("div: %i / %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("div: %i / %i\n", peek(stack, 2), peek(stack, 1));
|
||||||
@ -124,7 +119,7 @@ void execute(struct program program) {
|
|||||||
if (debug == 1) printf("rsf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
if (debug == 1) printf("rsf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||||
*stack.current = fp;
|
*stack.current = fp;
|
||||||
if (debug == 1) printf("pop: %i\n", peek(stack, 1));
|
if (debug == 1) printf("pop: %i\n", peek(stack, 1));
|
||||||
tempSlot = pop(stack);
|
tempSlot = pop(stack) ;
|
||||||
fp = tempSlot.u.number;
|
fp = tempSlot.u.number;
|
||||||
break;
|
break;
|
||||||
case POPL:
|
case POPL:
|
||||||
@ -137,18 +132,12 @@ void execute(struct program program) {
|
|||||||
break;
|
break;
|
||||||
case NE:
|
case NE:
|
||||||
if (debug == 1) printf("ne: %i != %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("ne: %i != %i\n", peek(stack, 2), peek(stack, 1));
|
||||||
if (getIntValfromStackSlot(pop(stack)) != getIntValfromStackSlot(pop(stack))) push(stack,
|
if (getIntValfromStackSlot(pop(stack)) != getIntValfromStackSlot(pop(stack))) push(stack, stackSlotWithObjRef(getIntObj(1)));
|
||||||
stackSlotWithObjRef(
|
|
||||||
getIntObj(
|
|
||||||
1)));
|
|
||||||
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
||||||
break;
|
break;
|
||||||
case EQ:
|
case EQ:
|
||||||
if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1));
|
if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1));
|
||||||
if (getIntValfromStackSlot(pop(stack)) == getIntValfromStackSlot(pop(stack))) push(stack,
|
if (getIntValfromStackSlot(pop(stack)) == getIntValfromStackSlot(pop(stack))) push(stack, stackSlotWithObjRef(getIntObj(1)));
|
||||||
stackSlotWithObjRef(
|
|
||||||
getIntObj(
|
|
||||||
1)));
|
|
||||||
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
||||||
break;
|
break;
|
||||||
case LT:
|
case LT:
|
||||||
@ -210,21 +199,21 @@ void execute(struct program program) {
|
|||||||
if (debug == 1) printf("new i: %i\n", i);
|
if (debug == 1) printf("new i: %i\n", i);
|
||||||
break;
|
break;
|
||||||
case DROP:
|
case DROP:
|
||||||
if (debug == 1) printf("drop\n");
|
if(debug ==1) printf("drop\n");
|
||||||
*stack.current = *stack.current - SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
*stack.current = *stack.current - SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
||||||
break;
|
break;
|
||||||
case DUP:
|
case DUP:
|
||||||
if (debug == 1) printf("dup\n");
|
if (debug==1) printf("dup\n");
|
||||||
tempObj = pop(stack).u.objRef;
|
tempObj = pop(stack).u.objRef;
|
||||||
push(stack, stackSlotWithObjRef(tempObj));
|
push(stack, stackSlotWithObjRef(tempObj));
|
||||||
push(stack, stackSlotWithObjRef(tempObj));
|
push(stack, stackSlotWithObjRef(tempObj));
|
||||||
break;
|
break;
|
||||||
case POPR:
|
case POPR:
|
||||||
if (debug == 1) printf("popr");
|
if (debug==1) printf("popr") ;
|
||||||
push(reg, pop(stack));
|
push(reg, pop(stack));
|
||||||
break;
|
break;
|
||||||
case PUSHR:
|
case PUSHR:
|
||||||
if (debug == 1) printf("pushr");
|
if(debug == 1) printf("pushr");
|
||||||
push(stack, pop(reg));
|
push(stack, pop(reg));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -245,7 +234,7 @@ int main(int argc, char *argv[]) {
|
|||||||
stack.size = &size;
|
stack.size = &size;
|
||||||
stack.current = ¤t;
|
stack.current = ¤t;
|
||||||
stack.stack = s;
|
stack.stack = s;
|
||||||
|
|
||||||
// Initialize the registery
|
// Initialize the registery
|
||||||
int rSize = SIZE;
|
int rSize = SIZE;
|
||||||
int rCurrent = 0;
|
int rCurrent = 0;
|
||||||
@ -278,7 +267,7 @@ int main(int argc, char *argv[]) {
|
|||||||
} else if (strcmp(argv[i], "--stack") == 0) {
|
} else if (strcmp(argv[i], "--stack") == 0) {
|
||||||
i++;
|
i++;
|
||||||
// TODO: implement stack size
|
// TODO: implement stack size
|
||||||
} else if (strcmp(argv[i], "--heap") == 0) {
|
} else if(strcmp(argv[i], "--heap") == 0) {
|
||||||
i++;
|
i++;
|
||||||
// TODO: implement heap size
|
// TODO: implement heap size
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user