🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.atari16
Article #1623

Yet another Megamax bug

#1623
From: braner
Date: Wed, 27 Aug 1986 01:09
72 lines
2724 bytes
[]

The following program will never exit:

-------------------------------------------------
#include <stdio.h>
long n;
subr()
{
	register int	j;
	j = (97 * n) / 12345;	/* integer result, long intermediate	*/
}
main()
{
	register long	i;
	for (i=0; i<0x20000; i++) {
		subr();
		if ((i&0xFFF) == 0)
			printf("t = %lx\n", i);
	}
}
------------------------------------------------

The reason is that subr() is compiled into: (excerpt)

	MOVE	D7,-(A7)	/* save the "register int j" space,        */
	MOVE.L	#97,D7		/*  but use it as "register long scratch", */
				/*  upper word of main's i gets clobbered! */
	...

(If you declare > 1 register, MOVEM.L ,-(A7) is used, so no problem.)
This is especially surprising because in MOST other cases the compiler
moves register vars into a scratch register (D0) before doing ANYTHING
with them, which is a waste of time and space.  For example:

	register int	i, k;
	i = i + k;

compiles into (even if mmimp'roved):

	MOVE	D7,D0
	ADD	D6,D0
	MOVE	D0,D7

You would think that that's because while evaluating "i + k", the
stupid compiler doesn't know yet that it is not going to keep the old
value of i, i.e. it could say "j = i + k". But look:

	register int	i, j, k;
	i = j + k;

compiles into:

	MOVE	D6,D7
	ADD	D5,D7

- i.e. in the former example the compiler is not stupid, just lazy!

Anybody at Megamax listening?

Disclaimer: Although I AM disappointed that I have to spend so much time
debugging a compiler I spent $200 on (and get no rebate...), I still think
that the Megamax compiler is the best we have right now.  But, if anybody
has had experience with the brand new Mark Williams compiler/shell, please
let us know! (bug density, speed of compilation, quality of code...)
At something like $125 for compiler AND shell it MIGHT be a bargain, unless
you have already spent your money on such things.  But then, the compiler
output products might work with the shell's I/O redirection...

- Moshe Braner

Corson Hall,  Cornell U.,  Ithaca  NY 14853    607-272-3487
Technical Details
Message-ID: <948@batcomputer.TN.CORNELL.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!cornell!batcomputer!braner
References: <8608251511.AA06093@ucbvax.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!cornell!batcomputer!braner
From: braner@batcomputer.TN.CORNELL.EDU (braner)
Newsgroups: net.micro.atari16
Subject: Yet another Megamax bug
Message-ID: <948@batcomputer.TN.CORNELL.EDU>
Date: Tue, 26-Aug-86 21:09:50 EDT
Article-I.D.: batcompu.948
Posted: Tue Aug 26 21:09:50 1986
Date-Received: Wed, 27-Aug-86 11:44:10 EDT
References: <8608251511.AA06093@ucbvax.Berkeley.EDU>
Reply-To: braner@batcomputer.UUCP (braner)
Organization: Theory Center, Cornell University, Ithaca NY
Lines: 72
Summary: If you use registers, use two!