RISC-V Test/Demo AUIPC

AUIPC

The AUIPC (Add Upper Immediate to Program Counter) instruction in RISC-V builds PC-relative addresses by adding a 20-bit upper immediate (shifted left by 12 bits with lower 12 bits filled with zeros) to the current program counter, placing the result in a destination register.

AUIPC Overview and Operation

Key Characteristics & Usage

Test/Demo Code

# ================================================================= # 32-bit architecture # ================================================================= # test/demo auipc # ================================================================= .data .text .global main # ----------------------------------------------------------------- # function: 99 # ----------------------------------------------------------------- func_99: # ------------------------------------------------------------- # function prologue # ------------------------------------------------------------- addi sp, sp, -4 # allocate stack frame sw ra, 0(sp) # save caller's return address # ------------------------------------------------------------- # function body # ------------------------------------------------------------- li a0, 99 # ------------------------------------------------------------- # function epilogue (returned is already in a0) # ------------------------------------------------------------- lw ra, 0(sp) # restore caller's return address addi sp, sp, 4 # de-allocate stack frame ret # return to caller # ----------------------------------------------------------------- # main # ----------------------------------------------------------------- main: call func_99 # call func_99 li a7, 10 # syscall, exit program ecall # syscall