Memory
Primary Memory of the CPU.
Source code in core/memory.py
class Memory:
"""
Primary Memory of the CPU.
"""
__slots__ = ("space",)
def __init__(self) -> None:
"""
Memory Constructor.
Attributes:
space (bytearray): A bytearray of size 4096 virtually representing CHP-8 memory.
"""
self.space: bytearray = bytearray(4096)
def load_binary(self, binary: bytes, offset: int = 0) -> None:
"""
Load bytes onto the RAM.
Arguments:
binary: a bytes object.
offset: From where to start loading the elements of the binary.
"""
for i, data in enumerate(binary):
self.space[i + offset] = data
__init__(self)
special
+
Memory Constructor.
Attributes:
Name | Type | Description |
---|---|---|
space |
bytearray |
A bytearray of size 4096 virtually representing CHP-8 memory. |
Source code in core/memory.py
def __init__(self) -> None:
"""
Memory Constructor.
Attributes:
space (bytearray): A bytearray of size 4096 virtually representing CHP-8 memory.
"""
self.space: bytearray = bytearray(4096)
load_binary(self, binary, offset=0)
+
Load bytes onto the RAM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
binary |
bytes |
a bytes object. |
required |
offset |
int |
From where to start loading the elements of the binary. |
0 |
Source code in core/memory.py
def load_binary(self, binary: bytes, offset: int = 0) -> None:
"""
Load bytes onto the RAM.
Arguments:
binary: a bytes object.
offset: From where to start loading the elements of the binary.
"""
for i, data in enumerate(binary):
self.space[i + offset] = data