RISCV RV32I Shifting >32 bit using two registers

Viewed 35

I want to write following C code using RISC V. It should shift a long long variable into a single result register. I have the value 0x181FFDC00 which cannot fit into a 32 bit register. Therefore I have to use two registers to store the value. A loop should shift the value multiple times, but how would I be able to handle the 0x1 in the second register?

This is what I have for now (not handling the overflow)

# long long value = 0x181FFDC00;
# int i = 0;
# do {
#     value = value >> 1;
#     i++;
# } while (i<9);

.globl main
.text

main:
    li s0, 0x181FFDC00      # s0 = 0x81FFDC00
    li s1, 0x0              # s1 = 0 (= i)
    li s2, 0x9              # s2 = 9 (condition for while loop)
        
    do:
        srli s0, s0, 0x1    # s0 = s0 > 1
        addi, s1, s1, 0x1   # i++
        blt s1, s2, do      # while i < 9
0 Answers
Related