Skip to content

Commit fb79a59

Browse files
committed
Refactored stack and instructions for better encapsulation
1 parent 5b0560b commit fb79a59

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

instructions.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
#include "registers.h"
66
#include "program.h"
77

8+
enum instructions {
9+
NOP,
10+
PUSH,
11+
POP,
12+
LOAD,
13+
STORE,
14+
JMP,
15+
JZ,
16+
JNZ,
17+
ADD,
18+
SUB,
19+
MUL,
20+
DIV,
21+
PRINT,
22+
STOP
23+
};
24+
825
uint16_t ip = 0;
926

1027
void inop(void)

instructions.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,6 @@
33

44
#include <stdint.h>
55

6-
enum instructions {
7-
NOP,
8-
PUSH,
9-
POP,
10-
LOAD,
11-
STORE,
12-
JMP,
13-
JZ,
14-
JNZ,
15-
ADD,
16-
SUB,
17-
MUL,
18-
DIV,
19-
PRINT,
20-
STOP
21-
};
22-
23-
extern uint16_t ip;
24-
25-
void inop(void);
26-
void ipush(int32_t element);
27-
void ipop(void);
28-
void iload(uint8_t reg);
29-
void istore(uint8_t reg);
30-
void ijmp(uint16_t position);
31-
void ijz(uint16_t position);
32-
void ijnz(uint16_t position);
33-
void iadd(void);
34-
void isub(void);
35-
void imul(void);
36-
void idiv(void);
37-
void iprint(void);
38-
void istop(void);
39-
406
void call_instruction(void);
417

428
#endif /* end of include guard: INSTRUCTIONS_H */

stack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdio.h>
33
#include "stack.h"
44

5+
static const int STACK_SIZE = 256;
6+
57
int32_t stack[STACK_SIZE];
68
uint8_t sp = 0;
79

stack.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33

44
#include <stdint.h>
55

6-
static const int STACK_SIZE = 256;
7-
8-
extern int32_t stack[STACK_SIZE];
9-
extern uint8_t sp;
10-
116
void stack_push(int32_t element);
127

138
int32_t stack_pop(void);

0 commit comments

Comments
 (0)