🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.arch
Article #2498

Re: Using C as an aid to hand writing assembler

#2498
From: Gregory Smith
Date: Mon, 12 May 1986 23:35
64 lines
3406 bytes
In article <491@rna.UUCP> dan@rna.UUCP (Dan Ts'o) writes:
>> 	Some years ago when I was learning 6800 assembler (anybody remember
>> D2 kits?) I used to first write everything in C and then hand compile it
>> into M6800 asm. ...
>> simplicity of the M6800 (dare I call it a RISC machine? :-)) makes this
>> easier than for something like a vax, but I can still do it; let's see:
>> 
>> 	char i, j;
>> 	j = 0;
>> 	for (i = 0; i <= 10; i++)
>> 	        j = j + i;
>> 
>> 	clr	j
>> loop1:  clr	i
>> 	cmp	i, #10
>> 	bge	out
>> 	lda	j
>> 	adda	i
>> 	sta	j
>> 	lda	i
>> 	inca
>> 	sta	i
>> 	bra     loop1:
>> out:
>
>	Not too good, I'm afraid. The loop1 label is misplaced - you "clr i"
>on every iteration. Also #10 is octal 8 instead of 10. You probably don't want
>the colon at the end of the "bra" statement. You don't want "bge out" but
>"bgt out" (since you say i <= 10). And finally, i and j should be local
>variables on the stack. I can see why your professor laughed.

If you must flame, do it properly. As I remember, in Motorola assembler,
10 is decimal, $10 is hex. Besides, you don't expect that sort of detail
in a news posting, do you? You missed the biggie completely: there is no
such thing as `cmp i,#10' in 6800 code. I believe `inc i' could have been
done, instead of lda/inc/sta.

Hand-compiling is definitely a good idea when a good compiler cannot
be had. When you write the C code, you deal at a reasonably high level
of abstraction; when you translate, you worry about details only and forget
the higher meaning. One major problem is with maintenance: when people
modify the assembler code, they don't bother changing the C code!

There are cases where real compilers cannot be had which are good enough.
If someone knows of a C compiler for Z80 or 8080 which can produce code
half as good as that produced by hand, I would like to hear about it. I
am sure it could be done - but nobody would pay you enough to make it
worth the effort. It would almost be an AI project!

While debugging, you have to figure out if bugs are caused by problems
in the C code ( many of these will be found during the hand-compile ) or
by incorrect compilation. If you have a real compiler, no matter how
horrible, you can often debug the C code with that before hand compiling,
and then hand-compile in stages. 'In stages' implies that the parameter
passing convention for the hand code follow that of the compiler, which
may not be desirable - especially on the kind of machine we are talking
about here.


-- 
"Canabee be said2b or not2b anin tire b, if half thabee isnotabee, due2
somain chunt injury?" - Eric's Dilemma
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Technical Details
Message-ID: <2763@utcsri.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
References: <817@harvard.UUCP> <491@rna.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
From: greg@utcsri.UUCP (Gregory Smith)
Newsgroups: net.arch
Subject: Re: Using C as an aid to hand writing assembler
Message-ID: <2763@utcsri.UUCP>
Date: Mon, 12-May-86 19:35:20 EDT
Article-I.D.: utcsri.2763
Posted: Mon May 12 19:35:20 1986
Date-Received: Wed, 14-May-86 01:11:09 EDT
References: <817@harvard.UUCP> <491@rna.UUCP>
Reply-To: greg@utcsri.UUCP (Gregory Smith)
Organization: CSRI, University of Toronto
Lines: 64