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

%hi & %lo not working #11

Open
dylanmc opened this issue Sep 11, 2019 · 1 comment
Open

%hi & %lo not working #11

dylanmc opened this issue Sep 11, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@dylanmc
Copy link

dylanmc commented Sep 11, 2019

After successfully getting "print 42 to the console" working, I'm trying to write hello world, and am getting assembler errors. Here's my code, adapted from gcc -s:

	.data
Hello:
	.string	"hello, world!"
	.text
	.align	1
	.globl	main
__start:
	lui	a1, %hi(Hello)   <- here the error says "got 3 arguments but expected 2)
	addi	a1, a1, %lo(Hello)  <- here it says got 4 expected 3
	addi    a0, x0, 4 # print_string
	ecall
	addi    a1, x0, 0
	addi    a0, x0, 17 # exit2
	ecall

I've looked at the ISA (no mention of the %hi/lo directives), and other locations - this seems to be an underdocumented aspect of RISC-V, but the current use of it is taken from how risc-v-gcc does it. What am I doing wrong, or is this a bug?

@dylanmc dylanmc changed the title lui & %hi not working %hi & %lo not working Sep 11, 2019
@TheThirdOne
Copy link

I've looked at the ISA (no mention of the %hi/lo directives), and other locations - this seems to be an underdocumented aspect of RISC-V, but the current use of it is taken from how risc-v-gcc does it.

%hi and %lo are builtin functions of the the GCC assembler; there is no need for an assembler for risc-v to implement those functions and be compliant.

What am I doing wrong, or is this a bug?

Neither, there are certainly several assemblers which will assembler your code, but venus doesn't support it.

If you want your code to be accepted by all assemblers you should write it with the pseudo-instruction la. In most cases handwritten code doesn't benefit from using %hi and %lo over standard pseudo-instructions.

For example,

        lui	a1, %hi(Hello)
	addi	a1, a1, %lo(Hello)

would be

      la a1, Hello

@ThaumicMekanism ThaumicMekanism added the enhancement New feature or request label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants