-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassembler.c
More file actions
81 lines (61 loc) · 2.59 KB
/
assembler.c
File metadata and controls
81 lines (61 loc) · 2.59 KB
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
/******************************************************************************
NAME - ELI BRACHA.
DATE - 2/3/2018
This Program Functions As Assembler For A specific Assembly Language.
University Project.
*******************************************************************************/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MINIMUM_ARGUMENTS 1
#define STARTUP_ERROR "Error: No File Paths Specified As Arguments.\n"
#define SUCCESS_MESSAGE "Build: Success Building Files.\n"
#define ERRROS_MESSAGE "Build: Failed Building Files Errors Count - %d.\n"
void initialize();
void assemble(char *);
void check_labels();
_Bool validate_files(char *);
void start_assembler(char **);
void write_code_list(char *);
void write_data_list(char *);
void write_ext_list(char *);
void write_ent_list(char *);
int main(int argc, char *argv[]) {
// Initializing All Known Limits For Commends (From Builder.c).
initialize();
// Deciding If A File Name Was Passed From The Commend Line.
argc > MINIMUM_ARGUMENTS ? start_assembler(argv) : printf(STARTUP_ERROR);
return 0;
}
// Variable To Share Errors And Decide If To Produce Files.
extern int ERRORS;
void start_assembler(char **files) {
while (*++files) {
if (validate_files(*files)) {
assemble(*files);
// Checking If No Error Found And Files Can Be Produced.
if (ERRORS == 0) {
check_labels();
char *code_data = (char *) malloc(sizeof(char) * strlen(*files));
char *ext = (char *) malloc(sizeof(char) * strlen(*files));
char *ent = (char *) malloc(sizeof(char) * strlen(*files));
strcpy(code_data, *files);
code_data[strlen(code_data) - 1] = 0;
code_data[strlen(code_data) - 2] = 0;
strcpy(ext, code_data);
strcpy(ent, code_data);
strcat(code_data, ".ob");
write_code_list(code_data); // Creating The Obj File (Code & Data).
write_data_list(code_data);
strcat(ext, ".ext");
write_ext_list(ext); // Creating The Ext File (extern).
strcat(ent, ".ent");
write_ent_list(ent);
if(ERRORS == 0)
printf(SUCCESS_MESSAGE); //Printing A Success Message.
}else{
printf(ERRROS_MESSAGE, ERRORS);
}
}
}
}