venus icon indicating copy to clipboard operation
venus copied to clipboard

%hi & %lo not working

Open dylanmc opened this issue 5 years ago • 1 comments

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 avatar Sep 11 '19 22:09 dylanmc

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

TheThirdOne avatar Oct 03 '19 00:10 TheThirdOne