diff --git a/build.sh b/build.sh index 59b9853..9272b00 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ mkdir ./bin -clang -o ./bin/r16e ./emu/main.c ./emu/cpu/ram.c ./lib/carg-parse/carg-parse.c \ No newline at end of file +clang -o ./bin/r16e ./emu/main.c ./emu/cpu/ram.c ./emu/cpu/register.c ./emu/cpu/stack.c ./lib/carg-parse/carg-parse.c \ No newline at end of file diff --git a/emu/cpu/instruction.c b/emu/cpu/instruction.c new file mode 100644 index 0000000..e409636 --- /dev/null +++ b/emu/cpu/instruction.c @@ -0,0 +1,41 @@ +#include "./instruction.h" + +r16_int GetArgVal(ArgumentInfo argInfo, r16_int arg) +{ + +} + +void ExecuteInstruction(CpuInstructions instruction, ArgumentInfo arg1Info, + ArgumentInfo arg2Info, r16_int arg1, r16_int arg2) +{ + switch (instruction) + { + case HLT: + printf("program halted\n"); + exit(0); + case ADD: + case SUB: + case MUL: + case DIV: + case LBS: + case RBS: + case BAN: + case BOR: + case BXO: + case BNO: + case PUS: + case POP: + case JMP: + case JEQ: + case JNZ: + case CAL: + case RET: + case REG: + case INT: + case INP: + case OUT: + case DIN: + case DOT: + case MOV: + } +} \ No newline at end of file diff --git a/emu/cpu/instruction.h b/emu/cpu/instruction.h new file mode 100644 index 0000000..8cb3f5c --- /dev/null +++ b/emu/cpu/instruction.h @@ -0,0 +1,9 @@ +#ifndef EMU_CPU_INSTRUCTION_H +#define EMU_CPU_INSTRUCTION_H + +#include "../cpu_const.h" +#include "./ram.h" +#include "./register.h" +#include "./stack.h" + +#endif \ No newline at end of file diff --git a/emu/cpu/stack.c b/emu/cpu/stack.c index 3da01d0..cd378cd 100644 --- a/emu/cpu/stack.c +++ b/emu/cpu/stack.c @@ -1,13 +1,31 @@ #include "./stack.h" +#include +#include -r16_int pop() +r16_int StackPop() { #ifdef DO_STACK_CHECKS - if () + if (GetRegister(SP).u == 0) + { + fprintf(stderr, "STACK UNDERFLOW\n"); + exit(-1); + } #endif + + SetRegister(SP, (r16_int){ GetRegister(SP).u - 1 }); + return GetValue((r16_int){ GetRegister(SP).u + STACK_LOCATION }); } -void push(r16_int value) +void StackPush(r16_int value) { + #ifdef DO_STACK_CHECKS + if (GetRegister(SP).u >= STACK_SIZE) + { + fprintf(stderr, "STACK OVERFLOW\n"); + exit(-1); + } + #endif + SetValue((r16_int){ GetRegister(SP).u + STACK_LOCATION }, value); + SetRegister(SP, (r16_int){ GetRegister(SP).u + 1 }); } diff --git a/emu/cpu/stack.h b/emu/cpu/stack.h index 28e4111..dc34ab7 100644 --- a/emu/cpu/stack.h +++ b/emu/cpu/stack.h @@ -9,4 +9,7 @@ #define DO_STACK_CHECKS +r16_int StackPop(); +void StackPush(r16_int value); + #endif \ No newline at end of file