-
Notifications
You must be signed in to change notification settings - Fork 0
/
20141570.h
161 lines (128 loc) · 4.08 KB
/
20141570.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// TODO : order functions
// TODO : string handling function 중에서 입력이 NULL인 경우 처리 할 것
#ifndef __20141570__
#define __20141570__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
// TODO : 0x100000 -> MEMORY_SIZE
#define START_RAW_STR_PASS2 5
#define MAX_LEN_INPUT 100
#define MAX_LEN_COMMAND 10
#define NUM_OF_OPCODES 58
#define LEN_MNEMONIC 6
#define LEN_SYMBOL 10
#define LEN_OPERAND 64
#define MEMORY_SIZE 0x100000
#define SEND_ERROR_MESSAGE(str) printf("<%s> ERROR OCCUR!!\n", str)
#define SEND_ERROR_LINE(number) printf("%d LINE IS ERROR OCCUR\n", number)
#define ADDR_BOUNDARY(addr) ((addr) < 0x100000 ? (addr) : 0xFFFFF)
#define INTERMEDIATE_FILENAME "inter.asm"
#define LEN_TEXT_RECORD 61
#define LEN_OBJCODE 61
#define LEN_DISPSTR 14
// TODO : global variable 묶기
typedef struct _HIST{
struct _HIST * next;
char command_line[MAX_LEN_INPUT];
} hist_list;
typedef struct _HASH_LINK{
struct _HASH_LINK * next;
int opcode;
int format;
char mnemonic[LEN_MNEMONIC];
} op_list;
typedef struct _SYMBOL_TABLE {
struct _SYMBOL_TABLE * next;
int LOCCTR;
char * symbol;
} SYMTAB;
typedef struct _OPTAB {
int opcode;
int format;
char mnemonic[LEN_MNEMONIC];
} OPTAB;
typedef struct _symb {
char * symbol;
char * mnemonic;
char * operand;
} symbMnemOper;
struct addressingMode {
int n; // indirect addressing
int i; // immediate addressing
int x; // index addressing
int b; // base relative
int p; // pc relative
int e; // extended
};
struct modificationRecord {
struct modificationRecord * next;
int numOfHalfByte;
int LOCCTR;
};
struct reg {
int A;
int X;
int L;
int PC;
int SW;
int B;
int S;
int T;
int F;
};
OPTAB opcode_table[NUM_OF_OPCODES];
SYMTAB * symbol_table,
* complete_table;
op_list *table_head[20];
hist_list *history_head;
unsigned char memory[MEMORY_SIZE]; // 2^20
void command_help(void);
void command_dir(void);
void command_history(void);
void memory_print(int start_addr, int end_addr);
void command_dump(int start, int end);
void command_edit(int addr, int val);
void command_fill(int start, int end, int val);
void command_reset(void);
void command_opcode(const char * input_mnem, int * error_flag);
void command_opcodelist(void);
void command_assemble(const char * filename, int * error_flag);
void command_type(const char * filename, int * error_flag);
void command_symbol(void);
int getLOCCTR(const char * str);
int hash_func(const char * mnemonic);
void make_linking_table(op_list ** table_addr, int opcode, const char * mnemonic, int format);
int opcode_mnem(op_list * table, const char *mnemonic);
int format_mnem(op_list * table, const char *mnemonic);
int strtoi(const char * str, int* error_flag, int exponential);
int a2dec (const char * str, int * error_flag);
int assemblePass1(FILE * fpOrigin, int * prog_len);
// TODO : For using same fetch function used assemblePass1, make a function that find a location except LOCCTR
int assemblePass2 (const char * filename, int prog_len);
int searchSYMTAB(const char * symbol, int * LOCCTR);
void insert2SYMTAB(char * symbol, int LOCCTR);
void fetch_info_from_str(const char * str, symbMnemOper *infoSetFromStr);
void initFetchedInfoFromStr(symbMnemOper * infoSetFromStr);
void initObjectCode (char * objectcode);
void initTextRecord (char * textRecord);
void initAddressingMode(struct addressingMode * modeFlag);
void initRegister(struct reg * regSet);
void insert2modificationRecord(struct modificationRecord **mRecord, int LOCCTR, int numOfHalfByte);
int analyseBYTE(const char * strBYTE, int * byteLength);
int isCommentLine(const char * str);
int isDirective(const char * str);
int isRegisterContainWhat(const char * operand, struct reg regSet, int * infoInReg);
char * fetch_filename_extension (const char * filename);
void sortSYMTABandPrint();
// TODO : DELETE SYMBOL TABLE FUNCTION
// TODO : DEALLOCATING sth FUNCTIONS 필요함!!
/* error handling */
int error_check_comma (int i,int comma_flag);
int error_check_moreargv (const char * input_str, int idx_input_str);
/* deallocate */
void deallocate_history(void);
void deallocate_opcode(void);
#endif