-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalss.py
96 lines (72 loc) · 2.21 KB
/
globalss.py
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
import array as arr
# GLOBAL VARIABLES
# for making .mc file
RtypeWords = ['add', 'and', 'or', 'sll', 'slt', 'sra', 'srl', 'sub', 'xor', 'mul', 'div', 'rem']
ItypeWords = ['addi', 'andi', 'ori', 'lb', 'ld', 'lh', 'lw', 'jalr']
StypeWords = ['sb', 'sw', 'sd', 'sh']
SBtypeWords = ['beq', 'bne', 'bge', 'blt']
UtypeWords = ['auipc', 'lui']
UJtypeWords = ['jal']
PC_label = []
name_label = []
PC = 0
PC_Seq = []
reg_step = []
memory_step = []
# buffer=-1
# register_file=-1
# particular_instruction=-1
memory_array = arr.array('i', [])
stack_array = arr.array('i', [])
stack_pointer = 10000
register = arr.array('i', [])
PC_execution = 0
def assign_register():
q = 0
while q < 32:
register.append(0)
q = q + 1
return
def assign_memory():
q = 0
while q < 1000: # -1 means that block of byte has not been used yet
memory_array.append(-1)
q = q + 1
return
def assign_PC():
PC_execution = 0
return
def assign_stack():
q = 0
while q < 10001:
stack_array.append(-1)
q = q + 1
return
# for reading .mc files
R = ['add', 'and', 'or', 'sll', 'slt', 'sra', 'srl', 'sub', 'xor', 'mul', 'div', 'rem']
I_1 = ['addi', 'andi', 'ori']
I_2 = ['lb', 'ld', 'lh', 'lw']
I_3 = ['jalr']
S = ['sb', 'sw', 'sd', 'sh']
SB = ['beq', 'bne', 'bge', 'blt']
U_lui = ['lui']
U_auipc = ['auipc']
UJ = ['jal']
reg = []
major_opcode_name = ['R', 'I_1', 'I_2', 'I_3', 'S', 'SB', 'U_lui', 'U_auipc', 'UJ']
major_opcode_value = ['0110011', '0010011', '0000011', '1100111', '0100011', '1100011', '0110111', '0010111', '1101111']
Rfun3 = ['000', '111', '110', '001', '010', '101', '101', '000', '100', '000', '100', '110']
Rfun7 = ['0000000', '0000000', '0000000', '0000000', '0000000', '0100000', '0000000', '0100000', '0000000', '0000001',
'0000001', '0000001']
I_1fun3 = ['000', '111', '110']
I_2fun3 = ['000', '011', '001', '010']
Sfun3 = ['000', '010', '011', '001']
SBfun3 = ['000', '001', '101', '100']
# rough work
# import linecache
# line = linecache.getline('assembly.txt', 1)
# i=1
# while i<=16:
# line = linecache.getline('assembly.txt', i)
# print(line)
# i=i+1