address data
-------------------------
0xad 0x59
0xae 0xfa
0xaf 0x9d
oxb0 0xa6
0xb1 0x78
0xb2 0x04
oxb3 0xbc
oxb4 0x88
0xb8 0xff
the MIPS code:
addi $s1, $zero, 0xab
lb $t0, 5($s1)
lw $t1, 5($s1)
addi $s1, $s1, 11
lbu $t2, -8($s1)
lw $t3, -8($s1)

wat will the hexadecimal value be of registers $t0, $t1, $t2,$t3,after executing the above codes, if the system is using little-endian byte order?

Dani AI

Generated

Quick clarification and a worked-through result (addresses in hex).

The alignment rule applies to the effective address (base + offset), not to the immediate alone — so whether lw is legal depends on (base+offset) % 4 == 0. Little-endian means the byte at the lowest address is the least-significant byte of a 32-bit word; a 4-byte word read from addresses b0..b3 becomes (b3<<24)|(b2<<16)|(b1<<8)|b0.

With $s1 = 0xab:

  • The byte load at 5($s1) reads address 0xb0. That byte is 0xa6, and lb sign-extends it to 0xFFFFFFA6.
  • The word load at the same effective address is permitted because 0xb0 is word-aligned; the four bytes at 0xb0..0xb3 (low->high: a6 78 04 bc) produce the 32-bit value 0xBC0478A6 on a little-endian machine.

After adding 11 to $s1 ($s1 becomes 0xb6):

  • lbu -8($s1) targets 0xae, reads 0xfa and zero-extends to 0x000000FA.
  • lw -8($s1) would try to load a word from 0xae. That address is not 4-byte-aligned (mod 4 = 2) and will cause an address-error exception on a standard MIPS implementation — the load does not produce a normal register value.

Practical tips: to handle unaligned words either align the pointer before lw, assemble the word from four lbu results with shifts/ORs, or use the lwl/lwr pair which is designed for unaligned accesses. was right to flag alignment issues, but be careful: you must check the effective address, not just the immediate offset.

You can't load word

lw $t1, 5($s1)

becouse 5 isn't divisable with 4 so you also can't do this

addi $s1, $s1, 11

and then

lw $t3, -8($s1)

the rest is correct so $t0 is 0xFFFFFF9d and $t2 is 0x000000fa. For learning MIPS you can use SPIM (yes revers from MIPS) simulator.
Whole asm code

# FAKULTET TEHNICKIH NAUKA NOVI SAD 
# KATEDRA ZA RACUNARSKU TEHNIKU I MEDJURACUNARSKE KOMUNIKACIJE
#################################################
#								text segment										#
#################################################

	.text		
	.globl main 
	
main:										# ovde pocinje izvrsavanje
	la $s1, dat1
	lb $t0, 5($s1)
#	lw $t1, 5($s1) # greska (error)
	addi $s1, $s1, 11
	lbu $t2, -8($s1)
#	lw $t3, -8($s1) # error


#################################################
#     	 	segment podataka                      #
#################################################

	.data
dat1: .byte 0xad 0x59 0xae 0xfa 0xaf 0x9d 0xb0 0xa6 0xb1 0x78 0xb2 0x04 0xb3 0xbc 0xb4 0x88 0xb8 0xff

##
##
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.