QtSpim probably misbehaves when loading a value of a .byte element

27 Views Asked by At

I have a university assignment and I have been given this data:

.data 
a: .word 10
e: .word 3, 2, 1, 0
c: .word -1
d: .byte -1,0,0,0

The question is: What's the value $4 is holding if we implement the code ... and why:

la $10,d
addi $10,$10,-12
lw $4,0($10)

I wanted to check the answer before answering theoretically and when I ran the code:

.data
a: .word 10
e: .word 3, 2, 1, 0
c: .word -1
d: .byte -1, 0, 0, 0
.text
.globl main

main:
la $10,d
addi $10,$10,-12
lw $4,0($10)

li $v0,1
move $a0,$4
syscall

li $v0,10
syscall

QtSpim says the output is 1 but I thought the output should be -1. I proceeded to check with chatgpt first and it confirmed my answer:

Do any of you have any idea whether me/chatgpt are wrong or there is something going wrong with QtSpim?

1

There are 1 best solutions below

0
stratakos On

I figuered out what went wrong, obviouslt me and chatgpt were wrong about this one since the "d: .byte -1,0,0,0" is capturing 4 bytes of memory and "c: .word -1" another 4 bytes. Finally the "e: .word 3,2,1,0" is capturing a total of 16 bytes which means that the operation $10-12 brought me to e[2] which holds the value of 1.