This is "doing it manually" to generate static addresses, as a workaround for the MARS assembler lacking %hi(symbol)
and %lo(symbol)
to get the linker to fill in the 4097
(0x1001
) from the high half of the address of Alength
and Aarray
, and the 4 and 8 from the low half of those addresses.
This code assumes that MARS will put the .data
section at 0x10010000
, like it says on the line with the .data
directive.
The two strings happen to add up to 4 bytes total, so the word values are already word-aligned. This code leaves out a .align
directive, even though it would have ended up being zero bytes (until you add another string and your word load breaks).
If you compile this C on the Godbolt compiler explorer:
int x = 1; // with no initializer it goes in the .bss as .space 4
int foo() { return x; }
MIPS gcc5.4 -O3 gives you this asm (some noise is stripped away):
foo():
lui $2,%hi(x)
lw $2,%lo(x)($2)
j $31
nop # IDK why it didn't put the load in the branch-delay slot; clang does
.data
.p2align 2 # actually gcc uses .align 2 but I disambiguated
x:
.word 1
$2
is $v0
, the return value in the standard MIPS calling convention.