I have been testing the following code on RiscV with the RV32I and RV64I assembler.
The assembly source file is
.text
slli x31,x31,63
When I assemble for 32 bit targets I obtain the following machine code output.
03ff9f93 slli x31,x31,0x3f
A warning is thrown but it appears the upper 7 bits of the instruction word are not 'reserved'. Doing a quick hand assembly I would expect 01ff9f93
. I realize that it is incorrect to use the immediate operand value of 63 but the assembler will write the 63 value anyway. This does not seem like correct operation.
One way to avoid this potential problem is to set the assembler command line option of --fatal-warnings
. And the build process will halt. But at a -warn
level it appears the 7 upper bits of the 32 target for the 'slli' command can be overwritten and you can create a legitimate RV64I instruction.
To keep the build simple for this test, I did the following.
- Created source file - "test.s"
Copied source file to the bin directory of the RiscV 32 bit build. Then,
./riscv32-unknown-elf-as -L --fatal-warnings test.s
or
./riscv32-unknown-elf-as -L -warn test.s
Create list file
./riscv32-unknown-elf-objdump -h -l -M numeric,no-aliases -S -d -EL a.out
The lower lines of output will look something like this below if you set -warn level in the assembler.
Disassembly of section .text:
00000000 <.text>:
0: 03ff9f93 slli x31,x31,0x3f
I am wondering why the assembler takes this approach and shouldn't the upper 7 bits for 'slii' with RV32I always be stuck-at 0?