Reputation: 161
Recently, I am working on RV32I base instruction set, and I did not find any instruction looks like LD r1, imm. Thus, I am wondering how assembly programer load an immediate to a register in RV32I system? Thanks.
To do so, programmer could use ADDI r1, r0, imm. Since r0 is a constant 0, so this instruction move imm to register r1.
I have no idea if the designers of RV32I think this way, use ADDI to replace LD r1, imm?
Hope anyone could shed some lights on it. Thanks.
Upvotes: 7
Views: 20115
Reputation: 1085
There is a li
(load immediate) alias or pseudo instruction that provides the functionality you are referring too.
The following example shows the li pseudo instruction which is used to load immediate values:
.equ CONSTANT, 0xdeadbeef li a0, CONSTANT
Which, for RV32I, generates the following assembler output, as seen by objdump:
00000000 <.text>: 0: deadc537 lui a0,0xdeadc 4: eef50513 addi a0,a0,-273 # deadbeef <CONSTANT+0x0>
This snippet is from this github markdown that is a good reference when programming in riscv assembly. https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md#load-immediate
Upvotes: 8