forked from royshaked/Assembly_Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_trans.c
More file actions
59 lines (56 loc) · 1.65 KB
/
Copy pathsecond_trans.c
File metadata and controls
59 lines (56 loc) · 1.65 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "code_table.h"
#include "symbol_table.h"
#include "second_trans.h"
#include "first_trans.h"
#define MAX 81
#define A 4
#define R 2
#define E 1
int second_trans(char* am_file, symbol_table **symbol_list, code_table **code_list)
{
code_table *temp = *code_list;
symbol_table *symbol_temp;
int error = 0;
while (temp)
{
/* Edit the address of the empty label */
if (is_bword_empty(temp->bword) && temp->dataORstring != 5)
{
symbol_temp = get_symbol(*symbol_list, temp->symbol);
if (symbol_temp == NULL)
{
printf("ERROR: symbol do not exist\n");
error = 1;
return error;
}
/* Case the label has & to calculate the distance */
if (temp->dataORstring == 3)
{
if (symbol_temp && symbol_temp->address != 0)
{
edit_bword(symbol_temp->address - temp->address + 1, temp->bword, 3, 23);
edit_bword(A, temp->bword, 0, 2);
}
}
/* Case is extern */
else if (symbol_temp->address == 0)
{
edit_bword(E, temp->bword, 0, 23);
}
/* Edit the label address */
else
{
/* Edit the label address */
edit_bword(symbol_temp->address, temp->bword, 3, 23);
/* Edit the R */
edit_bword(R, temp->bword, 0, 2);
}
}
temp = temp->Next;
}
return 0;
}