diff options
Diffstat (limited to 'components/ram.py')
| -rw-r--r-- | components/ram.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/components/ram.py b/components/ram.py index b6258e3..dd99ada 100644 --- a/components/ram.py +++ b/components/ram.py @@ -34,19 +34,25 @@ class Ram: """ Write data to memory based Mic-1 architecture """ - addr=self.c["MAR"] + addr=self.c["MAR"]*4 # Don't forget MAR address 32bits block of memory if addr>self.lastAddr: raise ValueError("You get out of the ram by trying to set a value at address {}, max address is {}".format(addr,self.lastAddr)) - self.data[addr]=self.c["MDR"] + #### Little endian #### + self.data[addr]=self.c["MDR"] & 0xFF + self.data[addr+1]=self.c["MDR"] & 0xFF00 + self.data[addr+2]=self.c["MDR"] & 0xFF0000 + self.data[addr+3]=self.c["MDR"] & 0xFF000000 + def read(self): """ Read data from memory based Mic-1 architecture """ - addr=self.c["MAR"] + addr=self.c["MAR"]*4 # Don't forget MAR address 32bits block of memory value=None try: - value=self.data[addr] + #### Little endian #### + value=(self.data[addr+3]<<24)|(self.data[addr+2]<<16)|(self.data[addr+1]<<8)|self.data[addr] except: if addr>self.lastAddr: raise ValueError("You get out of the ram by trying to get value at address {}, max address is {}".format(addr,self.lastAddr)) @@ -77,11 +83,11 @@ class Ram: #print("{}:{}".format(key,bin(value)[2:])) print("{}:{}".format(key,value)) - def dumpRange(self,start,end): + def dumpRange(self,start,end,step): """ Another dump helper """ - for i in range(start,end+1): + for i in range(start,end+1,step): try: print("{}:{}".format(i,self.data[i])) except: |
