-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_step.py
77 lines (67 loc) · 2.38 KB
/
driver_step.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
import linecache
import sys
from converttomachinecode1 import *
from decode1 import *
from error_handling import *
from execute0 import *
from fetch0 import *
from memoryaccess1 import *
from registerupdate1 import *
def myFunc():
assign_labelled_instruction()
globalss.assign_register()
a = error_handling()
if a == 1:
print('not passed')
sys.exit()
print('passed')
convert_to_machinecode()
globalss.assign_memory()
globalss.assign_stack()
file2 = open('machinecode.txt', 'r')
i = 1
each = str(linecache.getline('machinecode.txt', i)) # Execution will be done now
while each != '':
print((each))
global reg
each = each.split()
PC_Seq.append(globalss.PC_execution) # new
if (len(each) == 1):
reg_step.append(register.tolist()) # new
memory_step.append(memory_array.tolist()) # new
globalss.PC_execution = globalss.PC_execution + 4
i = int(globalss.PC_execution / 4) + 1
each = (linecache.getline('machinecode.txt', i))
continue
lii = fetch(each)
reg = decode(lii)
reg = determine_exact_instruction(lii,
reg) # now exact instruction name will be appended #reg[rd,rs1,rs2,imm,type,oriname]
reg = execute(reg)
reg = memoryaccess(reg) # a new value has been appended. We will use this value in regsiter update
# reg[rd,rs1,rs2,imm,type,oriname,execute_result,memoryaccessreult]
registerupdate(reg)
print(reg)
i = int(globalss.PC_execution / 4) + 1
print(i)
each = (linecache.getline('machinecode.txt', i))
reg.clear()
# print("Current register")
# print(globalss.register)
# print("Current memory")
# print(globalss.memory_array)
reg_step.append(register.tolist()) # new
memory_step.append(memory_array.tolist()) # new
# globalss.reg_step.append(globalss.register)
# globalss.memory_step.append(globalss.memory_array)
globalss.register[0] = 0
file2.close()
print(globalss.memory_array)
print("$$$$$$$$$$$$$")
print(PC_Seq)
print(register)
print("^^^^^^")
print(reg_step)
# print(memory_step)
if __name__ == '__main__':
myFunc()