Add little endianess, debug memory addressing

This commit is contained in:
Loic GUEGAN 2018-09-01 19:09:48 +02:00
parent 94377da94d
commit 4a9d274fd7
4 changed files with 16 additions and 18 deletions

View file

@ -27,7 +27,6 @@ class Caretaker:
elif value > (2**8) and key=="MBR" and key=="MBRU": # Check value fit in byte
print("Warning byte overflow: value {} on register {}".format(value,key))
value=value%256 # Force to fit in byte
self.objects[key]=value
def items(self):

View file

@ -1,9 +1,6 @@
from components.ijvm import ijvm
# TODO: Switch MAR as 32bits address (multiply its value by for)
# then same for SP and LV
class Microprogram:
def __init__(self,components):
@ -164,7 +161,7 @@ class Microprogram:
print("-------------- RAM --------------")
self.c["RAM"].dump()
print("------------- Stack -------------")
self.c["RAM"].dumpRange(self.c["LV"],self.c["SP"])
self.c["RAM"].dumpRange(self.c["LV"]*4,self.c["SP"]*4,4) # Convert address to 32bits value
print("----------- Registers -----------")
for key,value in self.c.items():
if key!="RAM":

View file

@ -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:

10
ram.txt
View file

@ -1,9 +1,5 @@
BIPUSH
1
7
BIPUSH
0
GOTO
0
0
BIPUSH
30
8
IADD