diff --git a/CMakeLists.txt b/CMakeLists.txt index d648b47..f1186eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,7 @@ set(CMAKE_C_STANDARD 99) add_compile_options(-g -Wall -pedantic) +include_directories("./bigint/build/include") + add_executable(ninja njvm.c SDA.c) diff --git a/Makefile b/Makefile index f56f609..452f957 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CC = gcc # program to Run -F = prog.bin +F = programs/prog1.bin # Compiler flags CFLAGS = -g -Wall -Ibigint/build/include diff --git a/njvm.c b/njvm.c index 226326b..ecf1c1b 100644 --- a/njvm.c +++ b/njvm.c @@ -9,6 +9,7 @@ #include "SDA.c" #include "debugMenu.c" #include "bigint.h" + // Debug int debug = 0; @@ -49,7 +50,7 @@ void execute(struct program program) { StackSlot tempSlot; ObjRef tempObj; 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) { case HALT: if (debug == 1) printf("halt\n"); @@ -59,8 +60,11 @@ void execute(struct program program) { push(stack, stackSlotWithObjRef(getIntObj(SIGN_EXTEND(IMMEDIATE(program.program[i]))))); break; case ADD: - if (debug == 1) printf("add: %i + %i\n",peek(stack, 2),peek(stack, 1)); - push(stack, stackSlotWithObjRef(getIntObj(getIntValfromStackSlot(pop(stack)) + getIntValfromStackSlot(pop(stack))))); + if (debug == 1) printf("add: %i + %i\n", peek(stack, 2), peek(stack, 1)); + bip.op1 = pop(stack).u.objRef; + bip.op2 = pop(stack).u.objRef; + bigAdd(); + push(stack, stackSlotWithObjRef(bip.res)); break; case SUB: if (debug == 1) printf("sub: %i - %i\n", peek(stack, 2), peek(stack, 1)); @@ -69,7 +73,8 @@ void execute(struct program program) { break; case MUL: if (debug == 1) printf("mul: %i * %i\n", peek(stack, 2), peek(stack, 1)); - push(stack, stackSlotWithObjRef(getIntObj(getIntValfromStackSlot(pop(stack)) * getIntValfromStackSlot(pop(stack))))); + push(stack, stackSlotWithObjRef( + getIntObj(getIntValfromStackSlot(pop(stack)) * getIntValfromStackSlot(pop(stack))))); break; case DIV: if (debug == 1) printf("div: %i / %i\n", peek(stack, 2), peek(stack, 1)); @@ -119,7 +124,7 @@ void execute(struct program program) { if (debug == 1) printf("rsf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); *stack.current = fp; if (debug == 1) printf("pop: %i\n", peek(stack, 1)); - tempSlot = pop(stack) ; + tempSlot = pop(stack); fp = tempSlot.u.number; break; case POPL: @@ -132,12 +137,18 @@ void execute(struct program program) { break; case NE: if (debug == 1) printf("ne: %i != %i\n", peek(stack, 2), peek(stack, 1)); - if (getIntValfromStackSlot(pop(stack)) != getIntValfromStackSlot(pop(stack))) push(stack, stackSlotWithObjRef(getIntObj(1))); + if (getIntValfromStackSlot(pop(stack)) != getIntValfromStackSlot(pop(stack))) push(stack, + stackSlotWithObjRef( + getIntObj( + 1))); else push(stack, stackSlotWithObjRef(getIntObj(0))); break; case EQ: if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1)); - if (getIntValfromStackSlot(pop(stack)) == getIntValfromStackSlot(pop(stack))) push(stack, stackSlotWithObjRef(getIntObj(1))); + if (getIntValfromStackSlot(pop(stack)) == getIntValfromStackSlot(pop(stack))) push(stack, + stackSlotWithObjRef( + getIntObj( + 1))); else push(stack, stackSlotWithObjRef(getIntObj(0))); break; case LT: @@ -199,21 +210,21 @@ void execute(struct program program) { if (debug == 1) printf("new i: %i\n", i); break; case DROP: - if(debug ==1) printf("drop\n"); + if (debug == 1) printf("drop\n"); *stack.current = *stack.current - SIGN_EXTEND(IMMEDIATE(program.program[i])); break; case DUP: - if (debug==1) printf("dup\n"); + if (debug == 1) printf("dup\n"); tempObj = pop(stack).u.objRef; push(stack, stackSlotWithObjRef(tempObj)); push(stack, stackSlotWithObjRef(tempObj)); break; case POPR: - if (debug==1) printf("popr") ; + if (debug == 1) printf("popr"); push(reg, pop(stack)); break; case PUSHR: - if(debug == 1) printf("pushr"); + if (debug == 1) printf("pushr"); push(stack, pop(reg)); break; } @@ -234,7 +245,7 @@ int main(int argc, char *argv[]) { stack.size = &size; stack.current = ¤t; stack.stack = s; - + // Initialize the registery int rSize = SIZE; int rCurrent = 0; @@ -267,7 +278,7 @@ int main(int argc, char *argv[]) { } else if (strcmp(argv[i], "--stack") == 0) { i++; // TODO: implement stack size - } else if(strcmp(argv[i], "--heap") == 0) { + } else if (strcmp(argv[i], "--heap") == 0) { i++; // TODO: implement heap size } else { diff --git a/njvm.o b/njvm.o index 0390d91..d790adb 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/support.o b/support.o index b9bac9c..83da1f6 100644 Binary files a/support.o and b/support.o differ