Path: utzoo!attcan!uunet!mcvax!enea!kth!draken!tut!pl From: pl@tut.fi (Pertti Lehtinen) Newsgroups: comp.sys.m68k Subject: Re: Funny MC68000 programs Message-ID: <5403@korppi.tut.fi> Date: 23 Nov 88 10:41:28 GMT References: <17541@santra.UUCP> Reply-To: pl@tut.fi (Pertti Lehtinen) Organization: Tampere University of Technology, Finland Lines: 55 From article <17541@santra.UUCP>, by mat65@tukki.jyu.fi (Toivanen Jari): > Here are a couple of interesting problems for all those who think they can > progam the M68000 processor family. What does the following very interesting > program do ? > > a move.l #b,a0 > b move.l (a0),-(a0) > bra a+2 > This is tiny example of program crawling downward in memory. More classic example is same for PDP-11 mov -(pc),-(pc) with single instruction. On MC68000 we can do this too by b: lea a(pc),a0 a: move.l (a0),-(a0) bra b which is not so easy to spot as we do not jump into middle of intruction. > Second and perhaps kinkier question: why does the following program fail to do > the "opposite" of the first program ? > > move.l #a,a0 > a move.l (a0)+,(a0) > Move instruction takes only word, but long word is transferred, so instruction at a+2 does not get modified. Also prefetch could make us some tricks here. We may try something like: lea a(pc),a0 lea b(pc),a1 a: move.l (a0)+,(a1)+ b: bra b But this may not do anything useful, (does these anyway do) as I did not try. I do not have 68000 machine around and these forward crawling version do not work on 68020 machines as instruction cache does give us some troubles. ------------------------------------------------------------------------ pl@tut.fi ! All opinions expressed above Pertti Lehtinen ! are preliminary and Tampere University of Technology ! in subject to change Software Systems Laboratory ! without any further notice.