This tool simulates loads and stores by letting you choose the direction, size, endianness, extension, and address and seeing what will happen. All numbers in the diagram are in hexadecimal, even if they are not preceded by 0x.
This tool doesn’t work well on narrow screens. Please view it on a computer (or make your browser window wider if you’re already on one).
Registers
t0
0xAABBCCDD
t1
0x00000084
Memory
Values:
…
12
34
56
78
9A
BC
DE
F0
05
00
00
00
…
Addresses:
…
84
85
86
87
88
89
8A
8B
8C
8D
8E
8F
…
lw t0, (t1)
Steps performed by this instruction:
1. Check alignment
Is the address 0x00000084 a multiple of 4?
Yes! So go to the next step.
No! So this instruction crashes with an alignment error.
2. Get 4 byte(s) from memory
The byte(s) we loaded: 0x12, 0x34, 0x56, 0x78
2. Truncation
Only the lower 16 bits (2 byte(s)) of the value will actually be put into memory. The upper bits are left behind.
2. Truncation
No truncation is performed for sw, because we are storing all 32 bits (4 Bytes) of the value.
3. Assemble by endianness
Little-endian means the first byte from memory becomes the the "little end" (least-significant byte) of the value.Big-endian means the first byte from memory becomes the "big end" (most-significant byte) of the value.
So the bytes above are assembled into 0x78563412.
3. Assemble by endianness
Endianness doesn't matter for lb or lbu because we are only loading one byte, so there is only one order it can possibly go in.
3. Split by endianness
Little-endian means the first byte stored into memory is the "little end" (least-significant byte) of the value.Big-endian means the first byte stored into memory is the "big end" (most-significant byte) of the value.
The value from t0 is split into these bytes in this order: 0x78, 0x56, 0x34, 0x12.
3. Split by endianness
Endianness doesn't matter for sb because we are only storing one byte, so there is only one order it can possibly go in.
4. Extension
The value is sign-extended to 32 bits. That means the most significant bit (the sign bit) of the loaded value is duplicated to the left.
4. Extension
The value is zero-extended to 32 bits. That means 0s are written in front of the loaded value to make it 32 bits in size.
4. Extension
No extension is performed for lw, because the value is already the right size for the register.
4. Store the value into memory
The bytes from the previous step are actually stored into memory.