Given these two example ASM files:
With comments:
addi s0 x0 10 # 0x00
loop:
addi s0 s0 -1 # 0x04
# comment
beq s1 x0 out # 0x08 # should jump to 0x08 + 8 = 0x10
# Another comment
beq x0 x0 loop # 0x0C # should jump to 0x0C - 8 = 0x04
out:
beq x0 x0 out # 10
Without comments:
addi s0 x0 10 # 0x00
loop:
addi s0 s0 -1 # 0x04
beq s1 x0 out # 0x08 # should jump to 0x08 + 8 = 0x10
beq x0 x0 loop # 0x0C # should jump to 0x0C - 8 = 0x04
out:
beq x0 x0 out # 10
the parser should give the same exact output. However, the respective outputs are:
['0x00a00413', '0xfff40413', '0x00048663', '0xfe0008e3', '0x00000063']
['0x00a00413', '0xfff40413', '0x00048463', '0xfe000ce3', '0x00000063']
When comments are present, relative jumps are respectively 12 and -16 instead of +8 and -8.
This seems to indicate that comments, although (correctly) not generating instructions, have an impact in the jump offset calculation.
Given these two example ASM files:
With comments:
Without comments:
the parser should give the same exact output. However, the respective outputs are:
['0x00a00413', '0xfff40413', '0x00048663', '0xfe0008e3', '0x00000063']
['0x00a00413', '0xfff40413', '0x00048463', '0xfe000ce3', '0x00000063']
When comments are present, relative jumps are respectively 12 and -16 instead of +8 and -8.
This seems to indicate that comments, although (correctly) not generating instructions, have an impact in the jump offset calculation.