Question

I don't understand the behaviour of this piece of MIPS code:

.data

x: .word 12
y: .word 14, -3
z: .ascii "CSE2021"
t: .byte 0x8a
v: .word y

.text
main:

addi $t0, $0, 0
lw $s0, y($t0)
lw $t0, v($0)
lw $s0, -4($t0)

jr $ra

There are several things bugging me:

  1. The task is to determine the value of $s0 at the end of execution. How can you do it?

  2. What does the line: v: .word y mean? Does it declare a char, why doesn't it have quotes?

  3. If I comment out everything in .data, but v:, the User Data Segment shows:

    User data segment [10000000]..[10040000] [10000000]..[1003ffff] 00000000

    Is there no data in it now?? Where's v then?

Thanks.

Was it helpful?

Solution

1) you do it by following what the processor would do:

addi $t0, $0, 0  # $t0 is now 0
lw $s0, y($t0)   # $s0 is now word from memory at address y+$t0 which is 14
lw $t0, v($0)    # $t0 is now word from memory at address v+$0 which is y
lw $s0, -4($t0)  # $s0 is now word from memory at address $t0-4=y-4=x which is 12 

2) y is a label, it means use y's address

3) if you only keep v it should produce a compilation error because y is undefined (unless your assembler automatically treats undefined symbols as external)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top