Added the option to test and basic math to execute()

This commit is contained in:
nilsplk 2023-10-21 19:14:48 +02:00
parent 7d7b67f7f2
commit 9f7b69e5f7

19
njvm.c
View File

@ -2,6 +2,10 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
//Comment to disable debug
#define DEBUG
#define IMMEDIATE(x) ((x) & 0x00FFFFFF) #define IMMEDIATE(x) ((x) & 0x00FFFFFF)
#define HALT 0 #define HALT 0
@ -72,14 +76,19 @@ void execute(void) {
case PUSHC: case PUSHC:
break; break;
case ADD: case ADD:
stackPush(stackPop()+stackPop());
break; break;
case SUB: case SUB:
stackPush(stackPop()-stackPop());
break; break;
case MUL: case MUL:
stackPush(stackPop()*stackPop());
break; break;
case DIV: case DIV:
stackPush(stackPop()/stackPop());
break; break;
case MOD: case MOD:
stackPush(stackPop()%stackPop());
break; break;
case RDINT: case RDINT:
break; break;
@ -93,8 +102,18 @@ void execute(void) {
i++; i++;
} }
} }
#ifdef DEBUG
void tests(){
printf("test\n");
}
#endif /* ifdef DEBUG */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
#ifdef DEBUG
tests();
#endif /* ifdef DEBUG */
if (argc > 1) useption(argc, argv); if (argc > 1) useption(argc, argv);
else { else {