This "does it manually" to generate static addresses, as a workaround for the MARS assembler, which lacks %hi(symbol)
and %lo(symbol)
for the linker to fill 4097
( 0x1001
) from the upper half of Alength
and Aarray
, as well as 4 and 8 of the bottom half of these addresses.
This code assumes that MARS will put the .data
section at 0x10010000
, as the line with the .data
directive says.
Two lines add up to 4 bytes, so the word values are already word aligned. This .align
code directive .align
, even if it ended with zero bytes (until you add another line and your word is not interrupted).
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 assm (some noise is removed):
foo(): lui $2,%hi(x) lw $2,%lo(x)($2) j $31 nop
$2
is $v0
, the return value in the standard MIPS calling convention.
source share