-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstruction_memory.py
More file actions
59 lines (42 loc) · 1.7 KB
/
instruction_memory.py
File metadata and controls
59 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from block import Block
from data import Data
class InstructionMemory(Block):
"""
Inputs:
- Addr - index adresy z Program Counteru
Outputs:
- Instrukce: - Přes splitter do dalších částí (RF)
- Celá instrukce (32 b) do IMM gen.
"""
def __init__(self, file_name, data: Data):
self.file_name = file_name
self.content = None
self.__load_machine_code()
super().__init__(data)
# self.() # Při inicializaci je potřeba náskok jednoho taktu
def init(self) -> None:
self.data.instruction = self.content[0]
def __load_machine_code(self) -> None:
"""
Load machine code from file
:return:
"""
with open(self.file_name) as f:
self.content = f.readlines()
self.content = [int(i.strip(), 16) for i in self.content]
# def state(self, location) -> None:
# self.data.instruction = self.content[location]
def clock_up(self) -> None:
addr = int(self.data.PC_to_IM / 4)
try:
self.data.instruction = self.content[addr]
# logger.info(f"new instruction loaded: {hex(self.data.instruction)} (address = {hex(self.data.PC_to_IM)})")
except IndexError:
assert Exception(f"ERROR: addr: {hex(addr)}, ins: {hex(self.data.instruction)}")
# Pokud se program zacyklil na konci:
if self.data.instruction == 0x6f:
self.data.running = False
# if self.data.instruction == 0x00e7a023:
# input()
# if __name__ == "__main__":
# instructionMemory = InstructionMemory("../APP.mhc", Data())