SCC.150 Assembler Emulator
A compiler for a simple assembler language
 All Files Functions
emulator.h
Go to the documentation of this file.
1 #ifndef EMULATOR_H_
2 #define EMULATOR_H_
3 
29 #include <stdio.h> // used for printf()
30 #include <stdlib.h> // used for atoi()
31 #include <stdbool.h> // used for bool data type
32 
33 #define MAX_PROG_LEN 99 // The maximum length (in lines) a program can have
34 #define MAX_LINE_LEN 80 // The maximum length of a program line (in characters)
35 #define MAX_OPCODE 10 // The maximum number of opcodes that are supported
36 #define MAX_REGISTER 4 // The maximum number of registers (minus INSP)
37 #define OPCODE_LENGTH 3 // The maximum length of an opcode
38 #define ARG_LENGTH 4 // The maximum length of an arg
39 #define OPCODE 0 // Used for parsing instruction segments
40 #define ARG1 1
41 #define ARG2 2
42 
43 // Opcode handling functions
44 int opcodeNOP(char* opcode, char* arg1, char* arg2);
45 int opcodeSET(char* opcode, char* arg1, char* arg2);
46 int opcodeAND(char* opcode, char* arg1, char* arg2);
47 int opcodeOR(char* opcode, char* arg1, char* arg2);
48 int opcodeADD(char* opcode, char* arg1, char* arg2);
49 int opcodeSUB(char* opcode, char* arg1, char* arg2);
50 int opcodeSHL(char* opcode, char* arg1, char* arg2);
51 int opcodeSHR(char* opcode, char* arg1, char* arg2);
52 int opcodeJMP(char* opcode, char* arg1, char* arg2);
53 int opcodePRT(char* opcode, char* arg1, char* arg2);
54 
55 // Argument extraction function
56 int getArg2(char* arg2);
57 
58 // Command validator function
59 bool isValid(char* opcode, char* arg1, char* arg2);
60 
61 // Emulator run functions
62 int execInstruction(char* instruction);
63 int execProgram();
64 int loadProgram();
65 
66 #endif /* EMULATOR_H_ */
int opcodeOR(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:172
int loadProgram()
Definition: emulator.c:466
int opcodeSET(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:124
int opcodeSHR(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:268
int opcodeNOP(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:107
int execInstruction(char *instruction)
Definition: emulator.c:388
int execProgram()
Definition: emulator.c:444
int opcodeSUB(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:220
int opcodeADD(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:196
int opcodeAND(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:148
int opcodePRT(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:311
int getArg2(char *arg2)
Definition: emulator.c:334
int opcodeSHL(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:244
bool isValid(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:352
int opcodeJMP(char *opcode, char *arg1, char *arg2)
Definition: emulator.c:291