AntonLydike / riscemu

RISC-V emulator in python
MIT License
48 stars 14 forks source link

Data OPs not working as intended #10

Closed niklasr22 closed 2 years ago

niklasr22 commented 2 years ago

If the highest bit of the value that should be stored with a data op is a 1, the following error will be thrown. The error does not depend on the data op.

Example:

        .data
test:   .byte 0xFF
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/riscemu/__main__.py", line 117, in <module>
    cpu.load_program(loader.parse())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/riscemu/parser.py", line 109, in parse
    return parse_tokens(self.filename, tokenize(f))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/riscemu/parser.py", line 54, in parse_tokens
    PARSERS[token.type](token, args, context)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/riscemu/assembler.py", line 203, in handle_instruction
    cls.add_bytes(size, parse_numeric_argument(arg), context)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/riscemu/assembler.py", line 176, in add_bytes
    content = bytearray(content.to_bytes(size, 'little', signed=not unsigned))
OverflowError: int too big to convert