Path: utzoo!attcan!utgpu!watmath!iuvax!rutgers!bellcore!wind!sdh
From: sdh@wind.bellcore.com (Stephen D Hawley)
Newsgroups: comp.lang.forth
Subject: Re: The Minimal Forth Machine
Message-ID: <17391@bellcore.bellcore.com>
Date: 11 Aug 89 20:53:09 GMT
References: <2241@dogie.macc.wisc.edu>
Reply-To: sdh@wind.UUCP (Stephen D Hawley)
Distribution: na
Organization: Bellcore, Morristown, NJ
Lines: 80

In article <2241@dogie.macc.wisc.edu> stevens@vms.macc.wisc.edu (PAul STevens -- MACC) writes:
>In article <1330@massormetrix.ida.liu.se>, mikpa@massormetrix.ida.liu.se (Mikael Patel) writes...
>In the limit you wind up with something about as efficient as a Turing
>machine.  But very complete.

I think perhaps you missed the point.  The original article mentioned that
this would be for student use to implement.  Efficiency is not really the
question, but educational value.

For example, I took an architecture class 2 semesters ago that covered the
advantages of RISC machines as part of the curriculum.  We were presented
the a machine called the Machester Mark I (which was a real machine --the
prof. gave us a program that simulated it).  It had the following instruction
set:
		BRA addr	-branch unconditional to addr
		BRL disp	-branch uncond with disp as a displacement
		LNG addr	-load the negation of the contents of addr
		STA addr	-store into addr
		SUB addr	-subtract the contents of addr
		SKN		-if negative, skip next instruction
		HLT		-halt

7 instructions.  That's all.  The prof had a contest to write the most
compact factorial.  Mine came in 3rd (3 bytes longer than the winner).
I also wrote an optimizing assembler for the machine.
Below is my entry, for your amusement and perusal.

This coming semester, I will be implementing a compiler for a FORTH-like
language.  Unlike most FORTH's, it will be suited to an environment which
doesn't take kindly to you poking around at the address space, FORGET
will not be so unforgiving (ie, only the function you want to forget will
go away, not everything defined afterwards), and much more planned.

Why?  Purely for educational reasons.

Oh dear.  I seem to have gone off the deep end here.

* factorial program for the MM I
* Steve Hawley
* has to be assembled at location 1!!
* uses the fact that the data for "zero" is really just a branch to 1
* manchasm -a 1 ... ...
fact    lng n
        skn
        hlt
        sta 501
        lng zero
        sta 500
        bra ment
mult    lng 500
        sub r
        sta 500
        lng 500
        sta 500
        lng 501
        sta 501
ment    lng 501
        sub one
        sta 501
        skn
        bra mult
        lng 500
        sta r
        lng r
        sta r
        lng n
        sta n
        lng n
        sub one
        sta n
* data section.  dat is a pseudo op
zero    dat 0 * this is actually a branch to location 1!!
one     dat 1
n       dat 4
r       dat 1

Steve Hawley
sdh@flash.bellcore.com
"Up is where you hang your hat."
	--Jim Blandy, computer scientist