forked from Sonalisinghal/Two-Pass-Assembler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assumptions.txt
84 lines (70 loc) · 3.54 KB
/
Assumptions.txt
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
Assumptions:
1. Macro is defined at the top of the file before the code where macro is used
2. Clear accumulator resets the accumulator. No address is present in the accumulator
3. Label table is used instead of symbol table as variables are not given, here symbol table will only have labels
4. Execution stops after the end statement. The code written after the end statement is not executed.
5. The maximum memory size= 12 bits
6. Operands:
1. For add,mul,lac,dsp and sub operand should be a defined address or a constant (cannot be an undefined address)
2. For brn , brz, brp should have a defined valid label
3. sac,inp should have a defined or undefined address (not a constant)
4. div should have first as defined address or constant, second and third can be defined or undefined address but not a constant
7. The number of parameters supplied to macro = number of parameters supplied during call
8. Label name cannot be an opcode name and cannot have a Macro name anywhere in it. For example if ADDTWO is a macro, then: "SUB","ADD","ADDTWOXYZ" are invalid Labels.
9. Comments ca be added with the help of ; or /
Design:
1. Data table contains all the addresses defined in the main code
2. Macro table contains the macro definition and the labels, parameters and instructions used in it
-- do we need this? 3. Opcode table is a list containing all the opcodes encountered in the main program stored in order
4. When a macro call is encountered, the instructions present in the macro table for the respective macro definition is substituted in the main instruction table
5. Explain the structure of the tables used
6. All the commands are converted to upper case, to avoid case errors.
Errors handled in first pass:
1. Multiple macro definitions
2. Invalid Label name (Label cannot have a macro name in it and it cannot be an opcode name)
3. Multiple label definitions
4. Address supplied should be of integer type.
5. Address supplied should be lesser than 12 bits=4096.
6. Incorrect number of parameters supplied in a macro
7. Incorrect number of parameters supplied for an opcode
8. END of program not found
9. MEND/ENDM for macro not found
10. Invalid opcode name/Macro name
Pseudocode for first pass:
declare END found variable
while instruction is available and END is not encountered:
if instruction empty line
skip line
if end
break
is instruction a comment
if yes remove comments
is instruction macro definition
put macro definition in dictionary
while mend is not encountered
add the instruction to macro table/dictionary
nextline
if mend is not encountered at all then throw error
what is the length of the instruction
does instruction[0] have a label of the form li:
if label is not previously defined:
if yes put it in the label label
else throw multiple definition error
in this case instruction[1] is opcode remaining is operand
else instruction[0] is opcode, remaining is operand
how many operands does the instruction have
which opcode does the instruction have
is the opcode a valid opcode
does the num of operands match the required number of operands for your opcode
if both yes put it in opcode table
append instruction in the table
else if is it a call to a macro
if yes put the parameters in a list
go to macro table and iterate over its instructions
substitute fields with given parameters
append substituted instruction in instruction Table
put the opcode in the opcode table
put label in label table
handle errors
if no throw incorrect number of operands error
Instruction add on every error