Add micro-instructions IFEQ and IFLT
This commit is contained in:
parent
4a9d274fd7
commit
cec2994481
2 changed files with 40 additions and 3 deletions
|
@ -145,6 +145,26 @@ class Microprogram:
|
||||||
elif opcode==ijvm["OUT"]:
|
elif opcode==ijvm["OUT"]:
|
||||||
self.fetch();self.c["PC"]+=1 # Fetch byte to push in MBR
|
self.fetch();self.c["PC"]+=1 # Fetch byte to push in MBR
|
||||||
print(str(chr(self.c["MBRU"])),end="") # MBRU because no char which are negative
|
print(str(chr(self.c["MBRU"])),end="") # MBRU because no char which are negative
|
||||||
|
elif opcode==ijvm["IFEQ"]:
|
||||||
|
self.c["SP"]=self.c["SP"]-1
|
||||||
|
self.c["MAR"]=self.c["SP"]
|
||||||
|
self.c["OPC"]=self.c["TOS"]
|
||||||
|
self.rd()
|
||||||
|
self.c["TOS"]=self.c["MDR"]
|
||||||
|
if self.c["OPC"]==0:
|
||||||
|
self.T()
|
||||||
|
else:
|
||||||
|
self.F()
|
||||||
|
elif opcode==ijvm["IFLT"]:
|
||||||
|
self.c["SP"]=self.c["SP"]-1
|
||||||
|
self.c["MAR"]=self.c["SP"]
|
||||||
|
self.c["OPC"]=self.c["TOS"]
|
||||||
|
self.rd()
|
||||||
|
self.c["TOS"]=self.c["MDR"]
|
||||||
|
if self.c["OPC"]<0:
|
||||||
|
self.T()
|
||||||
|
else:
|
||||||
|
self.F()
|
||||||
elif opcode==ijvm["HALT"]:
|
elif opcode==ijvm["HALT"]:
|
||||||
return(1)
|
return(1)
|
||||||
else:
|
else:
|
||||||
|
@ -154,6 +174,19 @@ class Microprogram:
|
||||||
raise RuntimeError("Instruction {} not found on address {}".format(opcode,self.c["PC"]-1))
|
raise RuntimeError("Instruction {} not found on address {}".format(opcode,self.c["PC"]-1))
|
||||||
return(0)
|
return(0)
|
||||||
|
|
||||||
|
def T(self): # This function is here just to follow ijvm implementation of "Structured Computer Organization"
|
||||||
|
self.fetch();self.c["PC"]+=1 # exactly like GOTO implementation
|
||||||
|
self.c["OPC"]=self.c["PC"]-1 # exactly like GOTO implementation
|
||||||
|
###### GOTO2 #####
|
||||||
|
self.c["H"]=self.c["MBR"]<<8
|
||||||
|
self.fetch();self.c["PC"]+=1 # Fetch second byte
|
||||||
|
self.c["H"]=self.c["MBRU"]|self.c["H"]
|
||||||
|
self.c["PC"]=self.c["OPC"]+self.c["H"]
|
||||||
|
##################
|
||||||
|
def F(self): # This function is here just to follow ijvm implementation of "Structured Computer Organization"
|
||||||
|
self.fetch();self.c["PC"]+=1 # Needed because memory access take 1 cycle in simulation
|
||||||
|
self.c["PC"]=self.c["PC"]+1
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
"""
|
"""
|
||||||
Print RAM, stack and registers
|
Print RAM, stack and registers
|
||||||
|
|
10
ram.txt
10
ram.txt
|
@ -1,5 +1,9 @@
|
||||||
BIPUSH
|
BIPUSH
|
||||||
|
-4
|
||||||
|
IFLT
|
||||||
|
0
|
||||||
|
4
|
||||||
|
BIPUSH
|
||||||
|
6
|
||||||
|
BIPUSH
|
||||||
7
|
7
|
||||||
BIPUSH
|
|
||||||
8
|
|
||||||
IADD
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue