#ifndef _PRCALC_H #define _PRCALC_H #include #include #include #define STACK_SIZE 1024 #define CARRY 1 #define NEGATIVE 2 #define OVERFLOW 4 #define UNSIGNED 8 typedef enum BOOL {FALSE, TRUE} _PRC_BOOL; /* * A -> general purpose register * B -> general purpose register * SP -> stack pointer. index where the stack is positioned * FLAGS -> 8 bit operation result flags (LSB) * 1 -> Carry bit * 2 -> Negative * 4 -> Overflow * 8 -> Unsigned * 16 -> * 32 -> * 64 -> * 128 -> */ typedef struct prc_registers { uint64_t A; uint64_t B; uint16_t SP; uint8_t FLAGS; } __prc_registers; typedef uint64_t __prc_stack[STACK_SIZE]; typedef struct prc_context { __prc_registers registers; __prc_stack stack; } prc_context; typedef enum PRC_ERROR {OK, STACK_OVERFLOW, STACK_EMPTY, STATE_UNDEFINED} PRC_ERROR; typedef enum PRC_OPERATION {ADD, SUB, MUL, DIV} __PRC_OPERATION; PRC_ERROR prc_init_context(prc_context *ctx); PRC_ERROR prc_push(prc_context *ctx, uint64_t val); PRC_ERROR prc_pop(prc_context *ctx, uint64_t *val); PRC_ERROR prc_set_a(prc_context *ctx, uint64_t val); PRC_ERROR prc_set_b(prc_context *ctx, uint64_t val); PRC_ERROR prc_swap(prc_context *ctx); PRC_ERROR prc_add_stack (prc_context *ctx); PRC_ERROR prc_mul_stack (prc_context *ctx); #endif //_PRCALC_H