Operations now work

This commit is contained in:
nilsplk 2023-10-21 21:09:01 +02:00
parent 9f7b69e5f7
commit 62ede37645

41
njvm.c
View File

@ -68,35 +68,48 @@ void useption(int argc, char *argv[]) {
void execute(void) {
int i = 0;
int intInput;
int temp;
char charInput;
while (programmSpeicher[i] != 0) {
switch (programmSpeicher[i] >> 24) {
case HALT:
break;
case PUSHC:
stackPush(IMMEDIATE(programmSpeicher[i]));
break;
case ADD:
stackPush(stackPop()+stackPop());
break;
case SUB:
stackPush(stackPop()-stackPop());
temp = stackPop();
stackPush(stackPop() - temp);
break;
case MUL:
stackPush(stackPop()*stackPop());
break;
case DIV:
stackPush(stackPop()/stackPop());
temp = stackPop();
stackPush(stackPop()/temp);
break;
case MOD:
stackPush(stackPop()%stackPop());
temp = stackPop();
stackPush(stackPop()%temp);
break;
case RDINT:
scanf("%i",&intInput);
stackPush(intInput);
break;
case WRINT:
printf("%i\n",stackPop());
break;
case RDCHR:
scanf("%c",&charInput);
stackPush(charInput);
break;
case WRCHR:
printf("%c\n",stackPop());
break;
}
i++;
@ -104,8 +117,28 @@ void execute(void) {
}
#ifdef DEBUG
void printStck(){
if(current >= 0) {return;}
printf("----\n");
for (int i = 0; i < current; i++) {
printf("|%i| \n",stack[i]);
}
printf("----\n");
}
void tests(){
printf("test\n");
printf("Runnig debug mode\n");
stackPush(10);
stackPush(15);
stackPush(13);
printStck();
current = 0;
programmSpeicher[0] = (RDINT << 24);
programmSpeicher[1] = (RDINT << 24);
programmSpeicher[2] = (MOD << 24);
programmSpeicher[3] = (WRINT << 24);
execute();
printStck();
}
#endif /* ifdef DEBUG */