rdeioris / necroassembler

A Python framework for building assemblers, includes ready-to-use modules for 6502, 8086, mips32 and many more
MIT License
6 stars 1 forks source link

Error with label value when assembly with 6502 #1

Open DoctorWho406 opened 1 year ago

DoctorWho406 commented 1 year ago

Hi, I am trying to compile my file written for 6502 with the necroassembler

necro_6502.exe Assemblyes/6502/Snake/Snake.S Assemblyes/6502/Snake/Snake.bin

but every time I issue the command I get this error message:

Traceback (most recent call last): File "C:\Users\lollo\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\lollo\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Documents\AIV\III Anno\venv\Scripts\necro_6502.exe__main__.py", line 7, in File "D:\Documents\AIV\III Anno\venv\lib\site-packages\necroassembler\assembler.py", line 825, in main asm.link() File "D:\Documents\AIV\III Anno\venv\lib\site-packages\necroassembler\assembler.py", line 261, in link self._resolve_labels() File "D:\Documents\AIV\III Anno\venv\lib\site-packages\necroassembler\assembler.py", line 237, in _resolve_labels raise NotInBitRange(true_address, total_bits, label) necroassembler.exceptions.NotInBitRange: label "game" with value -130 is not in the 8 bit range

This is my file

I noticed that if I delete 3 lines of code (apparently at random) the error disappears

Any advice?

rdeioris commented 1 year ago

Branches have 8 bits offset. You cannot jump higher than 127 bytes and lower than -128. You need to restructure your code for respecting this limit

DoctorWho406 commented 1 year ago

Ok, so if you move lines 115 to 118 to line 28 should it work?

Thank you so much

ldo commented 1 year ago

This is why you need to understand the quirks of the machine that you are writing assembly language for. Nothing is hidden from you!