Added Instruktions

This commit is contained in:
nils polek 2023-12-06 18:03:07 +01:00
parent 6ea2a7e735
commit 77cae7467e
3 changed files with 64 additions and 0 deletions

View File

@ -22,5 +22,14 @@
#define RSF 14
#define PUSHL 15
#define POPL 16
#define EQ 17
#define NE 18
#define LT 19
#define LE 20
#define GT 21
#define GE 22
#define JMP 23
#define BRF 24
#define BRT 25
#endif /* ifndef INSREUKTION */

31
njvm.c
View File

@ -112,6 +112,37 @@ void execute(struct program *program, struct sda *sda) {
currentFrame = stack.frames[stack.currentFrame];
currentFrame->fp[SIGN_EXTEND(IMMEDIATE(instruction))] = pop(&stack);
break;
case EQ:
push(&stack,pop(&stack)==pop(&stack));
break;
case NE:
push(&stack,pop(&stack)!=pop(&stack));
break;
case LT:
push(&stack, pop(&stack)<pop(&stack));
break;
case LE:
push(&stack,pop(&stack)<=pop(&stack));
break;
case GT:
push(&stack, pop(&stack)>pop(&stack));
break;
case GE:
push(&stack,pop(&stack)>=pop(&stack));
break;
case JMP:
i = SIGN_EXTEND(IMMEDIATE(instruction));
break;
case BRF:
if (pop(&stack)==0){
i = SIGN_EXTEND(IMMEDIATE(instruction));
}
break;
case BRT:
if (pop(&stack)==1){
i = SIGN_EXTEND(IMMEDIATE(instruction));
}
break;
}
}

View File

@ -75,6 +75,30 @@ void printProgram(struct program *program) {
case POPL:
strcpy(c, "popl");
break;
case EQ:
strcpy(c,"eq");
break;
case NE:
strcpy(c,"ne");
break;
case LT:
strcpy(c,"lt");
break;
case GT:
strcpy(c,"gt");
break;
case GE:
strcpy(c,"ge");
break;
case JMP:
strcpy(c,"jmp");
break;
case BRF:
strcpy(c, "brf");
break;
case BRT:
strcpy(c,"brt");
break;
default:
strcpy(c, "ERROR");
break;