What is the value x12 at the end of the execution of this instruction in RISC-V? (WITHOUT RARS)

116 Views Asked by At

I need to know what is the value of x12 knowing that x13=10 ( without using rars ) these are the code lines

loop:
blt x13,x0,EXIT
addi x13,x13, -1
addi x12,x12,2
jal x0, loop
exit:
1

There are 1 best solutions below

2
BEANefiT On

This is the loop with the counter x13. So you do 11 iterations and increase x12 by 2 in each iter.

If x12 was initialised with 0, then it will equal 22 after the loop.

Below is C equivalent of your code.

while(1) {
    if (x13 < 0)
        break;
    x13 -= 1;
    x12 += 2;
}

or

for (int x13 = 10; x13 >= 0; x13--)
    x12 += 2;