MIPS Assembly noob here using QTSPIM
.data
.byte 13
.byte 20
.byte 150
# Add the values up, compute the average, and store the result in a memory location.
.text
.globl main
lui $10, 0x1000 #loads the starting address of the data segment.
lb $t0, 0x10 ($10) #supposed to load 13 into $t0.
lb $t1, 0x14 ($10) #supposed to load 20 into $t1
add $t1, $t0, $t1 #adds the values of t0 and t1 and stores the result in t1
lb $t2,0x18 ($10) #supposed to load 150 into $t1
add $t1, $t1,$t2 #adds the values of t1 and t2 and stores the result in t1.
sb $t1, 0x22 ($10) #supposed to store the result in address 0x1022, expecting
# result = 183
I know i'm doing something wrong, but i'm not sure whether it's the addressing, or something else. Any help would be greatly appreciated. Thanks whenever i run the program in QTSPIM, it sometimes loads the first byte correctly, and shows "d" in register 8, but doesn't add or load anythings else correctly. when i attempt to run it again, sometimes it shows a different value (usually a hex) in the same register.
I amended the coded to:
.data
.byte 13
.byte 20
.byte 150
# Add the values up, compute the average, and store the result in a memory location.
.text
.globl main
lui $t2, 0x1000 #loads the starting address of the data segment.
lbu $t0, 0x1 ($t2) #supposed to load 13 into $t0.
lbu $t1, 0x2 ($t2) #supposed to load 20 into $t1
lbu $t3, 0x3 ($t2) #supposed to load 150 into $t3
add $t4, $t0, $t1 #adds the values of t0 and t1 and stores the result in t1
add $t4, $t3,$t4 #adds the values of t1 and t2 and stores the result in t1.
sb $t4, 0x13 ($t2) #supposed to store the result in address 0x1022
but i'm still getting weird undesired numbers stored in the registers.
t0=14;
t1=96;
t2=10000000 (expected);
t3=0;
t4=aa.