Commit 2831c538 authored by Khoi Lam's avatar Khoi Lam 💬
Browse files

Done regfile

parent bca10857
'''
Implementation of a physical register file that you can read from and write to
'''
from pydigital.riscv_isa import regNumToName
from riscv_isa.isa import regNumToName
class RegFile():
......@@ -13,12 +13,11 @@ class RegFile():
return str(self.registers)
## TODO: complete read and write and __str__
def read(self, rs):
'''
rs: adress to read from (int)
'''
pass
return self.registers[rs]
def write(self, wa, wd, en):
'''
......@@ -26,10 +25,29 @@ class RegFile():
wd: content to write to an address
en: boolean value: 1 = write
'''
pass
if en == 0:
return
else:
if wa == 0:
return
else:
self.registers[wa] = wd
def display(self):
#Source: Prof. Marchiori
fmt_reg = lambda i: f"{self.registers[i]:09x}" if self.registers[i] != None else " xxxxxxx"
for y in range(0, 32, 4):
print(" ".join([f"{regNumToName(i).rjust(4)}: {fmt_reg(i)}" for i in range(y, y+4)]))
if __name__ == "__main__":
wd = 0x14
en = 1
myRegFile = RegFile()
print(myRegFile)
#print(myRegFile.read(4))
registers = list(range(32))
for i in registers:
myRegFile.write(registers[i], wd+registers[i], en)
myRegFile.display()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment