简体   繁体   English

如何将立即数加载到 RV32I 基本指令集中的寄存器中?

[英]How to load an immediate number to a register in RV32I Base Instruction Set?

Recently, I am working on RV32I base instruction set, and I did not find any instruction looks like LD r1, imm.最近在研究RV32I基本指令集,没有发现像LD r1,imm的指令。 Thus, I am wondering how assembly programer load an immediate to a register in RV32I system?因此,我想知道汇编程序员如何将立即数加载到 RV32I 系统中的寄存器中? Thanks.谢谢。

To do so, programmer could use ADDI r1, r0, imm.为此,程序员可以使用 ADDI r1、r0、imm。 Since r0 is a constant 0, so this instruction move imm to register r1.由于 r0 是一个常数 0,所以这条指令将 imm 移动到寄存器 r1。

I have no idea if the designers of RV32I think this way, use ADDI to replace LD r1, imm?不知道RV32的设计者是不是这样想的,用ADDI代替LD r1,嗯?

Hope anyone could shed some lights on it.希望任何人都可以对此有所了解。 Thanks.谢谢。

There is a li (load immediate) alias or pseudo instruction that provides the functionality you are referring too.有一个 li(立即加载)别名或伪指令也提供您所指的功能。

The following example shows the li pseudo instruction which is used to load immediate values: .section .text .globl _start _start:以下示例显示了用于加载立即数的 li 伪指令:.section .text .globl _start _start:

 .equ CONSTANT, 0xcafebabe li a0, CONSTANT

which generates the following assembler output as seen by objdump:它生成以下汇编器输出,如 objdump 所见:

 0000000000000000 <_start>: 0: 00032537 lui a0,0x32 4: bfb50513 addi a0,a0,-1029 8: 00e51513 slli a0,a0,0xe c: abe50513 addi a0,a0,-1346

This snippet is from this github markdown that is a good reference when programming in riscv assembly.这个片段来自这个 github markdown,它是在 riscv 程序集中编程时的一个很好的参考。 https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md#load-immediate https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md#load-immediate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM