Compare commits
2 Commits
70dbd0253b
...
e5f2858a5c
| Author | SHA1 | Date | |
|---|---|---|---|
| e5f2858a5c | |||
| 906ea30be2 |
@ -5,5 +5,7 @@ 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 = prog.bin
|
F = programs/prog1.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.
19
njvm.c
19
njvm.c
@ -9,6 +9,7 @@
|
|||||||
#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;
|
||||||
|
|
||||||
@ -60,7 +61,10 @@ void execute(struct program program) {
|
|||||||
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));
|
||||||
push(stack, stackSlotWithObjRef(getIntObj(getIntValfromStackSlot(pop(stack)) + getIntValfromStackSlot(pop(stack)))));
|
bip.op1 = pop(stack).u.objRef;
|
||||||
|
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));
|
||||||
@ -69,7 +73,8 @@ 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(getIntObj(getIntValfromStackSlot(pop(stack)) * getIntValfromStackSlot(pop(stack)))));
|
push(stack, stackSlotWithObjRef(
|
||||||
|
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));
|
||||||
@ -132,12 +137,18 @@ 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, stackSlotWithObjRef(getIntObj(1)));
|
if (getIntValfromStackSlot(pop(stack)) != getIntValfromStackSlot(pop(stack))) push(stack,
|
||||||
|
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, stackSlotWithObjRef(getIntObj(1)));
|
if (getIntValfromStackSlot(pop(stack)) == getIntValfromStackSlot(pop(stack))) push(stack,
|
||||||
|
stackSlotWithObjRef(
|
||||||
|
getIntObj(
|
||||||
|
1)));
|
||||||
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
else push(stack, stackSlotWithObjRef(getIntObj(0)));
|
||||||
break;
|
break;
|
||||||
case LT:
|
case LT:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user