Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site harvard.ARPA
Path: utzoo!linus!philabs!cmcl2!seismo!harvard!breuel
From: breuel@harvard.ARPA (Thomas M. Breuel)
Newsgroups: net.micro.68k,net.micro.apple
Subject: 68000 inconsistency
Message-ID: <5@harvard.ARPA>
Date: Sun, 5-Aug-84 23:41:33 EDT
Article-I.D.: harvard.5
Posted: Sun Aug  5 23:41:33 1984
Date-Received: Wed, 8-Aug-84 00:17:19 EDT
Organization: Aiken Computation Lab, Harvard
Lines: 35

Consider these two short pieces of 68000 Assembly language:

(1) 1000 MOVE.L #$04001008,A0	(2) 1000 JMP #$04001006,A0
    1006 JMP (A0)		    1006 LEA *-6,A0
    1008 LEA *-8,A0		    ...
    ...

One would expect (at least I did) A0 to contain the same value after
both LEA instructions. Reality on the 68000 (I tried it on a LISA and
a Mac) is different, though. In case (1), A0 contain $04001000, and in
case (2), A0 contains $00001000. I find this behaviour inconsistent.
Apparently, the program counter actually gets set to the 32bit number
in the first case, whereas only 24 bits are used in the second case. 

This feature is particularly noticable on the LISA and the MacIntosh,
on which most addressing is done PC-relative to make code
position-independent: PC-relative instructions use the whole 32 bits
of the program counter, and PC-relative jumps and jsr's preserve the
highest 8 bits, so that any setting of the 8 msb is preserved through
long sections of a program. The LISA/MacIntosh debugger, MWLB, however,
clears those 8 bits. Altogether, this can create pretty obscure bugs.

[The way I discovered this feature was when working on my "Infinite
Improbability Lisp Interpreter" for the MacIntosh: certain functions
called by the evaluator failed mysteriously, but only if they did not
contain debugger trace points. The RTS instruction at the end of these
subroutines restored the program counter to normality... If one of
these functions called the panic routine, though, all of a sudden the
reader and the interpreter would not recognise LISP anymore. Maybe I
should have chosen another name for the thing.]



			Thomas M. Breuel
	...{genrad!wjh12!tardis,allegra!harvard}!gallifrey!tmb