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)
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
if en == 0:
if wa == 0:
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()
registers = list(range(32))
for i in registers:
myRegFile.write(registers[i], wd+registers[i], en)
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