Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.sys.mips Subject: Re: Mips assembler question Message-ID: Date: 12 Jun 90 15:20:23 GMT References: <1380@quintus.UUCP> <1990Jun11.213554.15606@imax.com> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 68 In-reply-to: dave@imax.com's message of 11 Jun 90 21:35:54 GMT In article <1990Jun11.213554.15606@imax.com> dave@imax.com (Dave Martindale) writes: | 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. Note, the MIPS assembler does not even allow for subtraction when the items are in the same section, and are constant. For example: .data b: .word 0 .word 1 .word 2 #... diff: .word (.-b)/4 I suspect that part of the reason may be that the MIPS assembler reorganizes the code, and the first pass of the assembler doesn't have the means of telling the second pass to do the appropriate back patching after any rearrangement. I've also gnashed my teeth over the fact that the MIPS assembler does not allow instructions to be put into the data section. Finally, we just discovered the hard way, that the MIPS assembler screws up line numbers if you put non instructions (such as the table of lables for implementing a switch statement) into .text. This is because the line number information is based on a delta from the previous line, and the assembler doesn't count the non instructions in forming the delta's. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so