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