Add opcodes
This commit is contained in:
parent
84de7cd481
commit
739548d99f
4 changed files with 48 additions and 8 deletions
|
@ -9,7 +9,14 @@ class Caretaker:
|
|||
self.objects[reg]=0
|
||||
self.objects["RAM"]=None
|
||||
|
||||
def __getitem__(self,key): # TODO: Allow MBRU key and adapt its return value
|
||||
def __getitem__(self,key):
|
||||
if key=="MBRU": # If we ask for unsigned
|
||||
return(self.objects["MBR"] & 0x000000FF)
|
||||
elif key=="MBR": # If we ask for signed
|
||||
if self.objects["MBR"]>=0:
|
||||
return(self["MBRU"])
|
||||
else: # Send 2 complement if it's lower than 0
|
||||
return(self.objects["MBR"] & 0xFFFFFFFF)
|
||||
return(self.objects[key])
|
||||
|
||||
def __setitem__(self,key,value):# TODO: Do special treatment for MBR (allow only 2^8 value)
|
||||
|
|
|
@ -86,7 +86,7 @@ class Microprogram:
|
|||
self.c["MAR"]=self.c["SP"]
|
||||
self.c["H"]=self.c["TOS"]
|
||||
self.rd()
|
||||
self.c["TOS"]=(self.c["MDR"] and self.c["H"])
|
||||
self.c["TOS"]=(self.c["MDR"] & self.c["H"])
|
||||
self.c["MDR"]=self.c["TOS"]
|
||||
self.wr()
|
||||
elif opcode==ijvm["IOR"]:
|
||||
|
@ -94,7 +94,7 @@ class Microprogram:
|
|||
self.c["MAR"]=self.c["SP"]
|
||||
self.c["H"]=self.c["TOS"]
|
||||
self.rd()
|
||||
self.c["TOS"]=(self.c["MDR"] or self.c["H"])
|
||||
self.c["TOS"]=(self.c["MDR"] | self.c["H"])
|
||||
self.c["MDR"]=self.c["TOS"]
|
||||
self.wr()
|
||||
elif opcode==ijvm["SWAP"]:
|
||||
|
@ -107,6 +107,34 @@ class Microprogram:
|
|||
self.c["MAR"]=self.c["SP"]-1
|
||||
self.wr()
|
||||
self.c["TOS"]=self.c["H"]
|
||||
elif opcode==ijvm["ILOAD"]:
|
||||
self.fetch();self.c["PC"]+=1 # Fetch local variable to push onto the stack
|
||||
self.c["H"]=self.c["LV"]
|
||||
self.c["MAR"]=self.c["MBRU"]+self.c["H"]
|
||||
self.rd()
|
||||
self.c["SP"]+=1
|
||||
self.c["MAR"]=self.c["SP"]
|
||||
self.wr()
|
||||
self.c["TOS"]=self.c["MDR"]
|
||||
elif opcode==ijvm["ISTORE"]:
|
||||
self.fetch();self.c["PC"]+=1 # Fetch local variable offset where to store
|
||||
self.c["H"]=self.c["LV"]
|
||||
self.c["MAR"]=self.c["MBRU"]+self.c["H"]
|
||||
self.c["MDR"]=self.c["TOS"]
|
||||
self.wr()
|
||||
self.c["SP"]-=1
|
||||
self.c["MAR"]=self.c["SP"]
|
||||
self.rd()
|
||||
self.c["TOS"]=self.c["MDR"]
|
||||
elif opcode==ijvm["IINC"]:
|
||||
self.fetch();self.c["PC"]+=1 # Fetch local variable offset to inc
|
||||
self.c["H"]=self.c["LV"]
|
||||
self.c["MAR"]=self.c["MBRU"]+self.c["H"]
|
||||
self.rd()
|
||||
self.fetch();self.c["PC"]+=1 # Fetch inc value
|
||||
self.c["H"]=self.c["MDR"]
|
||||
self.c["MDR"]=self.c["MBR"]+self.c["H"]
|
||||
self.wr()
|
||||
elif opcode==ijvm["OUT"]:
|
||||
self.fetch();self.c["PC"]+=1 # Fetch byte to push in MBR
|
||||
print(str(chr(self.c["MBR"])),end="")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue