I want to load a byte by using the 'lb' instruction. In this case I want to use lb to load from the memory mapped address 0x180003fb. The address 0x180003fb is mapped to a serial device used to read/print to a console. However, for some reason I cannot communicate with this device.
Here's the instruction in question.
lb t1, 0x180003fb
That doesn't however load the value located at the address 0x180003fb, it simply stores the hexadecimal value into the register. in this case 0x18000000 (LSD byte). How can I load a value from an address? I've been searching around for about 13 hours now and read trough two MIPS assembly guides á 200 pages each, just saying in case someone thinks it's obvious and I should Google it : /
Thankful for help.
MIPS Assembly, loading value from address
Re: MIPS Assembly, loading value from address
Addresses are always signed 16-bit displacements relative to a register. You probably don't want to sign extend the byte read from the device, so you'd write:
Similarly, to store t1 into address 0x8009f000, you'd write:
Notice that in this case, the upper part of the address has to be incremented by one, since the lower part is negative.
If you just want to load or store into an address between 0xffff8000 and 0x7fff, you can skip the lui and use the register which various assemblers call zr, zero or 0 as the base address.
As you may already know, to load an arbitrary 32-bit value into a register, you use lui and addiu. Let's say you want to load 0xfedcba98 into v0. This becomes:
Although addiu stands for "add immediate unsigned", the operand is nevertheless sign extended.
Code: Select all
lui t1, 0x1800
lbu t1, 0x3fb(t1)
Code: Select all
lui at, 0x800a
sw t1, 0xf000(at)
If you just want to load or store into an address between 0xffff8000 and 0x7fff, you can skip the lui and use the register which various assemblers call zr, zero or 0 as the base address.
As you may already know, to load an arbitrary 32-bit value into a register, you use lui and addiu. Let's say you want to load 0xfedcba98 into v0. This becomes:
Code: Select all
lui v0, 0xfedd
addiu v0, v0, 0xba98