This repository has been archived by the owner on May 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeback.py
77 lines (66 loc) · 1.6 KB
/
writeback.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
from declarations import *
from bitstring import BitArray
def writeback():
#Control Signals
global Branch
global MemRead
global MemtoReg
# ALUOp
global MemWrite
global ALUSrc1
global ALUSrc2
global PCSrc
global PCReg #Signal if the PC is updated by the Register value
#Register File inputs and Outputs
global RegWrite
global ReadData1
global ReadData2
global ReadRegister1
global ReadRegister2
global WriteRegister
global WriteDataRegFile
#Immediate Generation
global ImmGenOutput
#ALU Control
global ALUControl
#ALUinputs
global ALU_input1
global ALU_input2
#PC
global PC
#Instruction Memory
global ReadAddress
global Instruction
#ALU output
global Zero
global LessThan
global GE
global ALUResult
#Data Memory
global Address
global WriteData
global ReadData
#Registers
global reg_file
#clock
global clock
#TempMem
global TempMem
#Exit
global EXIT
if(EXIT):
return
if(RegWrite == 1):
if(MemtoReg == 0):
WriteData = ALUResult
elif(MemtoReg == 1):
WriteData = BitArray(hex = ReadData).int
else:
WriteData = PC + 4
if(MemRead != 4):
reg_file['x' + str(WriteRegister)] = WriteData
else:
reg_file['x' + str(WriteRegister)] = BitArray(hex = ReadData[8:]).int
reg_file['x' + str((WriteRegister + 1) % 32)] = BitArray(hex = ReadData[0:8]).int
reg_file['x0'] = 0
print(reg_file)