50 lines
1.1 KiB
C
Executable File
50 lines
1.1 KiB
C
Executable File
//
|
|
// Created by Nils on 29.10.2023.
|
|
//
|
|
#ifndef REG
|
|
#define REG
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
struct reg {
|
|
int* size;
|
|
int* current;
|
|
unsigned int *stack;
|
|
};
|
|
|
|
void printStackR(struct reg stack, int fp) {
|
|
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
|
|
for (int i = 0; i < *stack.current; ++i) {
|
|
if(fp == i) printf("|FP|\n");
|
|
printf("|%i|\n", stack.stack[i]);
|
|
}
|
|
}
|
|
|
|
void pushR(struct reg s, unsigned int value) {
|
|
if (*s.current >= *s.size) {
|
|
printf("Stack Overflow\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
s.stack[*s.current] = value;
|
|
*s.current=*s.current + 1;
|
|
}
|
|
|
|
unsigned int popR(struct reg s) {
|
|
if (*s.current == 0) {
|
|
printf("Stack Underflow\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
*s.current = *s.current -1;
|
|
return s.stack[*s.current];
|
|
}
|
|
|
|
unsigned int peekR(struct reg s, int steps) {
|
|
if (*s.current - steps < 0) {
|
|
printf("Stack Underflow\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
return s.stack[*s.current - steps];
|
|
}
|
|
#endif
|