print each step format
This commit is contained in:
parent
0e8d507e36
commit
38813b42f2
@ -1 +0,0 @@
|
|||||||
|
|
31
src/ram.py
31
src/ram.py
@ -98,15 +98,40 @@ class Ram(object):
|
|||||||
else:
|
else:
|
||||||
self.current += 1
|
self.current += 1
|
||||||
|
|
||||||
|
def __register_to_str(register):
|
||||||
|
if register[0] == '@':
|
||||||
|
return f'{register[3]}@{register[2]}{register[1]}'
|
||||||
|
elif register[0] == 'value':
|
||||||
|
return f'{register[1]}'
|
||||||
|
else:
|
||||||
|
return f'{register[0]}{register[1]}'
|
||||||
|
|
||||||
|
def __instr_to_str(self, instr_number):
|
||||||
|
instr = self.instr[instr_number]
|
||||||
|
op = instr["args"][0]
|
||||||
|
number = f'{instr_number} :'
|
||||||
|
instr_str = f' {number: <6}{op}('
|
||||||
|
if op == 'JUMP':
|
||||||
|
instr_str += f'{instr["args"][1]})'
|
||||||
|
elif op == 'JL' or op == 'JE':
|
||||||
|
instr_str += f'{instr["args"][1]}, '
|
||||||
|
instr_str += f'{Ram.__register_to_str(instr["args"][2])}, '
|
||||||
|
instr_str += f'{Ram.__register_to_str(instr["args"][3])})'
|
||||||
|
else:
|
||||||
|
instr_str += f'{Ram.__register_to_str(instr["args"][1])}, '
|
||||||
|
instr_str += f'{Ram.__register_to_str(instr["args"][2])}, '
|
||||||
|
instr_str += f'{Ram.__register_to_str(instr["args"][3])})'
|
||||||
|
return instr_str
|
||||||
|
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
'''
|
'''
|
||||||
Run machine to completion
|
Run machine to completion
|
||||||
'''
|
'''
|
||||||
while self.current < len(self.instr):
|
while self.current < len(self.instr):
|
||||||
print(self.current+2)
|
instr_str = self.__instr_to_str(self.current)
|
||||||
#print(*self.instr[self.current]['args'])
|
|
||||||
self.instr[self.current]['op'](self, *self.instr[self.current]['args'])
|
self.instr[self.current]['op'](self, *self.instr[self.current]['args'])
|
||||||
print(self.work_registers)
|
print(f'{instr_str: <28}{self.work_registers}')
|
||||||
|
|
||||||
def generate_graph(self):
|
def generate_graph(self):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user