Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect beq jump address when comment lines are present #3

Open
chmousset opened this issue Aug 5, 2023 · 0 comments
Open

Incorrect beq jump address when comment lines are present #3

chmousset opened this issue Aug 5, 2023 · 0 comments

Comments

@chmousset
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant