Search code examples
assemblyarchitecture

Instructions for RISC-V(.word)


I am working in a lab about RISC-V, but I have trouble in understanding .word.
Here is the code:

.data
.word 2, 4, 6, 8
n: .word 9

.text
main:
    add t0, x0, x0
    addi t1, x0, 1
    la t3, n
    lw t3, 0(t3)
fib:
    beq t3, x0, finish
    add t2, t1, t0
    mv t0, t1
    mv t1, t2
    addi t3, t3, -1
    j fib
finish:
    addi a0, x0, 1
    addi a1, t0, 0
    ecall # print integer ecall
    addi a0, x0, 10
    ecall # terminate ecall

I know this is the assembly code to calculate the Fibonacci sequence, but I am confused in some codes.

.word 2, 4, 6, 8
n: .word 9

and

la t3, n
lw t3, 0(t3)

I don't understand .word, and I don't know why t3 is 9 either.


Solution

  • actually i encountered this problem when i studied cs61c. ".word" here means setting certain memory for this word. as for why t3 is 9, you can look the memory part in Venus. the address of t3 is 0x1000010 and its contents is 9. that's why load word form t3 is 9.