racerxdl / riscv-online-asm

RISC-V Online Assembler using Emscripten, Gnu Binutils
https://riscvasm.lucasteske.dev
39 stars 9 forks source link

Compile error when 12th bit of an immediate value is set #2

Closed nishtahir closed 1 year ago

nishtahir commented 1 year ago

Running this instruction seems to generate a compile error

addi x1, x0, 2048

file.s: Assembler messages:
file.s:6: Error: illegal operands `addi x1,x0,2048'

However, running this seems to work just fine.

addi x1, x0, 1024

OK!

I could be wrong, but I believe the immediate value should be 12 bits long.

racerxdl commented 1 year ago

You're correct, indeed it has 12 bit, but its a sign extended imediate value, so the range is - 2048 to 2047

nishtahir commented 1 year ago

Oh, I see. I forgot that the assembly value is signed. Thanks for clearing that up for me 😄.