This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MIPS assembly error


The following version of the code works perfectly:

===================================
.data
actives: .byte 0
         .byte 0
         .byte 0
         .byte 0
ker_stack: .byte 0
           .byte 0
           .byte 0
           .byte 0

.equ distance,(ker_stack-actives)

testloc: .word distance

.text
li $4,distance
===================================

I'm just unclear as to why one works and one doesn't.

Ian Lance Taylor wrote:
Jeff Baker <jbaker@qnx.com> writes:


I posted this question a while ago and didn't receive a response from
the list, so I'll try again.

Assemble the following code for MIPS (binutils 2.15.91):
===================================
.data
actives: .word 0
ker_stack: .word 0

.equ distance,(ker_stack-actives)

testloc: .word distance

.text
li $4,distance
===================================

And you get:

main.s: Assembler messages:
main.s:10: Error: absolute expression required `li'

Is this a bug in gas?


Unclear.

It is probably possible to make this work.  It may not be trivial.
There are very similar cases which would be very very hard to
implement correctly.

The basic problem is that "li" is not an instruction, it is a macro
which expands to different instruction sequences depending on the
second operand.  To make this simple, it currently requires an
expression which can be fully evaluated at the time the instruction is
seen.  In the above example, gas does have enough information when the
instruction is seen to evaluate the operand, at least in principle.
But minor changes to the example would make it impossible for gas to
determine the operand value at the time that it parses the
instruction, and handling that correctly would be very very hard.

A better answer would refer to some sort of specification of MIPS
assembly language and determine whether li is permitted to use
anything other than simple constants.  However, I do not know of any
such specification.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]