Newsgroups: comp.sys.mips
Path: utzoo!utgpu!watserv1!watcgl!imax!dave
From: dave@imax.com (Dave Martindale)
Subject: Re: Mips assembler question
Message-ID: <1990Jun11.213554.15606@imax.com>
Organization: Imax Systems Corporation, Oakville Canada
References: <1380@quintus.UUCP> <MEISSNER.90Jun6104100@curley.osf.org>
Date: Mon, 11 Jun 90 21:35:54 GMT

In article <1380@quintus.UUCP> mark@quintus.UUCP (Mark Spotswood)
writes:

| I have a question about memory initialization in Mips assember. I would
| like to initialize a memory location to contain a value which is the
| difference between the addresses of two other labels, something like this:
| 
| a:
| 	.word    b-c
| 
| where b and c are two other labels. If I use the above syntax, the Mips
| assembler will signal an error saying that the symbol 'c' must be an 
| absolute value.
| 
| The mips assembler will allow things like:
| 
| a:
| 	.word    b
| 
| or
| 
| a:
| 	.word    b-2
| 
| If the assembler can figure out what b and b-2 will be, why can't it figure
| out what b-c will be?  Is there a way to do what I want in Mips assember?

I don't know if this is true of the MIPS software specifically, but it
is a limitation with some systems:

Initializing a location in memory with the difference between two external
addresses requires some way for the assembler to tell the linker that it
should calculate the difference between two external symbols and store
the result in this location.  Some object file formats simply have
no way of specifying this computation.

For example, suppose you have an object file format that, for every
word of code generated, there is an associated tag that says one
of:

	- this word is absolute, do not relocate
	- this word is an offset from external symbol #N, add the value
	  of that external symbol at link time
	- this word is an offset from the beginning of the current module;
	  add in this module's starting address at link time

The offsets or absolute values are stored in the instruction stream,
and the relocation information is stored elsewhere.  This format is
simple, and has the ability to handle most of the normal sorts of
relocation that are needed.   However, since each chunk of relocation
information specifies at most *one* external symbol whose link-time value
can be added to the corresponding instruction-stream word, there is no
way to specify that the value of two symbols should be subtracted.

To allow the assembler and linker to handle constant expressions that
contain more than one reference to an address or size that is determined
at link time, the object file format must allow almost arbitrary expressions
to be passed between the assembler and the linker.
