How to use the lui op-code with variable label in ARMIPS assembler

Started by weissvulf, April 13, 2014, 07:25:44 PM

Previous topic - Next topic


This is for MIPS assembly: Is there a way to get the ARMIPS assembler to use a variable label with the lui (load upper immediate) op-code? The lui needs the upper two digits of the number and as far as I can tell, ARMIS will only isolate the lowest digits from a number.

What I'm trying to do is the same op as " li r2,Label " but with the lui separated from the addiu

Hope that makes sense  :-\


In that case you can just use "la r2,Label". It's a pseudo-opcode which resolves to a lui/addui pair.


Thank you for the reply mziab. I'm trying to make something of a jump table with a single lui at the top, and then a table of addiu depending on the circumstances. So I was hoping to separate the "load upper"  from the "add immediate", yet still use variable labels.

Here's a simplified example:

lui r4,TextBlock     ;load movable text block location upper

addiu r3,r0,0x1
beq r3,r2,CASE1
addiu r3,r0,0x201
beq r3,r2,CASE2
addiu r3,r0,0x2

CASE1: j 0x800338F8
addiu r4,r4,Text1    ;load movable text block location lower
CASE2: j 0x800338F8
addiu r4,r4,Text2    ;load movable text block location lower

Text1: .string "text1"
Text2: .string  "text2"


I recently added a feature to make this easier (so far only available in the GitHub repository):

li.u a0,label
li.l a0,label

The same is available for other two opcode macros. .u will only write the first opcode, .l only the second. If the upper half is the same you can also use it with different labels, though I wouldn't recommend that.

A simple table is probably best:
li r4,Table
sll r2,2h
addu r4,r2
lw r4,(r4)

.word Text1
.word Text2

If you REALLY want to keep your method, then consider something like this:

li r4,TextBlock

li r3,1h
beq r3,r2,@@case1
li r3,201h
beq r3,r2,@@case2
j @@next
addiu r4,(Text1-TextBlock)
j @@next
addiu r4,(Text2-TextBlock)

That will work as long as your text isn't more than 32kb away from the Beginning of TextBlock.


Thank you for the reply KC. I'm very glad ARMIPS is still in development. The tool is so impressive, that I jumped to using it exclusively for my translation project and abandoned all my custom tools formats.

Thank you also for the table example. That might actually be more efficient than what I was using. I'll have to do some thinking and count up the cycles. This particular snippet was designed to insert 'gender specific pronouns' into a text stream so the 'table' is a bit complicated by the need to factor in both the gender value  and then the specific pronoun's value. But, if I converted part of the process to a table like your example, it would allow for easy expansion if I wanted to auto insert other words.

There are areas where I have to move existing text tables around to make room for the translation - so I have to overwrite the original lui and there 's not room for a full li. The li.u li.l will work perfectly perfectly for that. Excellent!  :cookie: