added pushr popr

This commit is contained in:
nils polek 2024-01-14 17:39:11 +00:00
parent 94fb404c71
commit 23e787eb5e

18
njvm.c
View File

@ -14,6 +14,9 @@ int debug = 0;
struct stack stack; struct stack stack;
#define SIZE 1000 #define SIZE 1000
//Register
struct stack reg;
// Program // Program
struct program program; struct program program;
@ -194,6 +197,13 @@ void execute(struct program program) {
push(stack, temp); push(stack, temp);
push(stack, temp); push(stack, temp);
break; break;
case PUSHR:
//TODO
push(reg, SIGN_EXTEND(IMMEDIATE(program.program[i])));
break;
case POPR:
push(stack, pop(reg));
break;
} }
if (debug == 1) printf("=== DEBUG: Stack after instruction %i ===\n", i); if (debug == 1) printf("=== DEBUG: Stack after instruction %i ===\n", i);
@ -217,6 +227,14 @@ int main(int argc, char *argv[]) {
stack.current = &current; stack.current = &current;
stack.stack = s; stack.stack = s;
// Initialize the registery
int rSize = SIZE;
int rCurrent = 0;
unsigned int r[SIZE];
reg.size = &rSize;
reg.current = &rCurrent;
reg.stack = r;
// Initialize ProgrammSpeicher // Initialize ProgrammSpeicher
int psize = 1000; int psize = 1000;
int saveProgram = 0; int saveProgram = 0;