问题
I want to load 64 bit address into MIPS64 General Purpose Register(GPR). I can do it by
lui $at, LabelAddr[63:48]
ori $at, $at, LabelAddr[47:32]
sll $at, 16
ori $at, $at, LabelAddr[31:16]
sll $at, 16
ori $at, $at, LabelAddr[15:0]
But, Is there any other way to do it?
I got some information from this
But i want to know what is "constant pool" and how to create it and how to access it?
回答1:
The "simple" way is to let the assembler handle it using the dla
pseudoinstruction. It will expand to something like your code:
lui $dst, LabelAddr[63:48]
lui $at, LabelAddr[31:16]
daddiu $dst, $dst, LabelAddr[47:32]
daddiu $at, $at, LabelAddr[15:0]
dsll32 $dst, $dst, 0
daddu $dst, $dst, $at
A constant pool is an area of memory where you store your constants that can be addressed efficiently. Some assemblers and architectures have special support for this, on others you have to do things manually. As outlined in the answer to the question you linked, you can set up a pointer to your constant pool (using the above method) and use more efficient access for subsequent operations.
# load pool base address
dla $s0, pool
foo:
# just some placeholder
addu $t0, $t0, $t1
bar:
# load from pool
ld $a0, pool_foo($s0)
ld $a1, pool_bar($s0)
.section pool
# macro helper to define a pool entry
.macro ENTRY label
pool_entry_\label\(): .quad \label
.equ pool_\label\(), pool_entry_\label - pool
.endm
ENTRY foo
ENTRY bar
来源:https://stackoverflow.com/questions/17269218/is-there-any-simple-way-or-macro-to-load-64bit-address-into-mips64-gpr