Machine Problem 2 Supplement
22C:18, Spring 1996
Due Tuesday Feb. 27, 1995, in discussion
Douglas W. Jones
Notice: Extra credit will be given for support of full 32 bit
signed operands. Full credit will be given for those who limit the
stack to 16 bits.
Notice: The MAS system conforms to the sidenotes in the textbook
on the Macintosh programming environment; see particularly the note on page
235. This means:
- Your program consists of two segments, the code segment and the
data segment. These are not necessarily contiguous in memory.
- References to labels in the code segment are assembled using PC relative
addressing.
- Register A5 points to the base of the data segment. References to
labels in the data segment are automatically converted to indexed form using
A5 as the index register.
- DC directives referencing labels in either the code or data segment
do not contain the absolute addresses of the addressed items. Rather, they
contain the displacement of the addressed item from the start of the indicated
segment, and it is up to the programmer to use indexing or other forms of
address arithmetic to convert these relative addresses to absolute addresses.
As a consequence of this, the following two statements that would be
equivalent under the "normative" view of how assemblers should function
are not equivalent under MAS!
LEA X,A0
MOVE.L #X,A0
If X is a label in the data segment, the following code is equivalent
to the above LEA statement:
MOVE.L #X,A0
ADDA A5,A0
If X is a label in the code segment, and if A4 is a pointer to the base of
the code segment, the following code is equivalent to the above LEA statement:
MOVE.L #X,A0
ADDA A4,A0
To make A4 point to the start of the code segment, make your code segment
begin as follows:
START: LEA START,A4
Note that, in all of the above, if XP is defined as
XP: DC.L X, then MOVE.L #X,A0 is equivalent to
MOVE.L XP,A0.