-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
64 lines (56 loc) · 1.55 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdint.h>
#ifndef MAIN_H
#define MAIN_H
#define RET_SUCCESS 0
#define RET_FAILURE -1
#define NUM_ARRAYS 65536
/* Represents a standard 32-bit instruction. */
typedef struct
{
unsigned registerA :3;
unsigned registerB :3;
unsigned registerC :3;
unsigned :19;
unsigned opCode :4;
} Instruction;
/* Represents all possible 4-bit instruction opcodes. */
typedef enum
{
CONDITIONAL_MOVE = 0,
ARRAY_INDEX = 1,
ARRAY_UPDATE = 2,
ADDITION = 3,
MULTIPLICATION = 4,
DIVISION = 5,
NAND = 6,
HALT = 7,
ALLOCATION = 8,
DEALLOCATION = 9,
OUTPUT = 10,
INPUT = 11,
LOAD_PROGRAM = 12,
LOAD_IMMEDIATE = 13
} OpCode;
/* Global references for unit-testing. */
extern uint32_t Registers[];
extern uint32_t *Programs[];
extern size_t ProgramSize[];
/* Function Prototypes */
int Init(int argc, char **argv);
void PrintUsage(char *programName);
void LoadFile(const char *filePath, uint32_t **programArray, size_t *size);
Instruction ParseInstruction(uint32_t instruction);
void ConditionalMove(Instruction inst);
int ArrayIndex(Instruction inst);
int ArrayUpdate(Instruction inst);
void Add(Instruction inst);
void Multiply(Instruction inst);
int Divide(Instruction inst);
void Nand(Instruction inst);
int Allocate(Instruction inst);
int Deallocate(Instruction inst);
int Output(Instruction inst);
int Input(Instruction inst);
int LoadProgram(Instruction inst);
void LoadImmediate(uint32_t inst);
#endif /* MAIN_H */