
Documentation for spp   (assembly language preprocessor)
	written by Dale Luck

This preprocessor was written for the Motorola family 68k family.

It adds 7 structured instructions to the assembler.

These instructions are if/else/endif
                       repeat/until
                       while/whend

The use of these constructs makes assembly code much more readable
and maintainable as well as makes it easier to write in the first
place.

I wrote this preprocessor about 7 years ago when the 68000 first
came out and I found out the the cmp/bxx pair did not work the
way I thought was intuitive. For example
If I want #1 to be moved into d7 if d1>d0 then

I wrote
	cmp	d1,d0
	ble	foo
		moveq	#1,d7
foo:

	I expected the 68k to take the branch if d1 was le to d0.
	But NNOOOOOOOO!
	It takes the branch if d0 is le to d1.

	Instead, I now write:

	if d1>d0
		moveq	#1,d7
	endif

This has a couple advantages:
	I now see that d7 is loaded with #1 if d1>d0 as well as I did
	not have to think up another stupid label that I will never
	use again. Also note that I can now line my indentations up
	so that I can match my endifs up if withs and make sure I've
	closed all my flow control logic.

I supposed your wondering what spp generates:
	In the last case, it will generate:
	cmp	d1,d0
	bgt.s	if000001	; or some such label
		moveq	#1,d7
if000001:

	It automatically makes forward branches short. Which is what
	I need in 80% of all my code. When the branch is too long,
	the assembler complains, and then I fix it with a modifier.

Modifiers are little key characters that begin with a '.'.

	For instance to make the example a long branch I use .ex
	if d1>d0 .ex
	If I wanted to make the comparison a long comparison I use
	if d1>d0.l
	I can have more than one modifier on the line so

	if d1>d0.b	.ex
		a whole bunch of assembly code
	else	.ex
		a whole more bunch of code
	endif

For whend and until, it never generates a short branch since the
branch is backward. The assembler should be able to figure out
if it can use a short branch.

Spp looks for special cases. For example,
	if d1>#0.l
will generate
	tst.l	d1
	ble	ifxxxxxx
However thanks to the 68k's well thought out instructions, you have
to use
	if #0<a0.l
the it will generate
	cmp.l	#0,a0
It looks for the second variable being #0 to use the tst instructions.

You can also treat variables like booleans.
	if d0
Will generate
	tst	d0
	beq	if00000
Assuming you want to execute the body of the if statement if d0 is nonzero.

If you are clever enough to have the condition codes of the 68k already
setup so that you do not need the tst or compare. for example

	move.l	d0,d1	; sets condition codes
	if >
	endif
Will insert a ble in there, figuring you want to execute the body if
	d1 is greater than zero
If you need to get real down and dirty you can use some more special
modifiers.
	add.l	d0,d0	; will shift d0 left by one
	if .cs
	endif
Will do the body if the carry flag was set.
In general all the .ge .le .lt, .cc etc are legal here
You are not limited to using registers and immediate values for your
relation. However it must be able to replaced by a simple compare
instruction. so
if sign is a memory location, you can use
	if sign>#0
to generate
	tst.l	sign
	ble	ifxxxxxx
If MinX is an offset into some kind of structure you can use
	if MinX(a0)>d0.l
to generate
	cmp.l	MinX(a0),d0
	ble	ifxxxxxx

The keywords if,until,while require a relational expression.
The other keywords are just branch targets.

The relational expression can take many forms. The relational
expression must be able to be reduced to a single cmp or tst
instruction. I've found that this takes care of 90% of all
cases where I need to control the flow of my program. For those
more complex cases, it is not difficult to break it down into
a couple instructions.

legal modifiers
	.ex		make branch into long branch (suppress .s)
	.l		make comparison a long
	.b		make comparison a byte
	.w		make comparison a word
	.u		make comparison unsigned

legal modifiers/relations
	.cs		carry set
	.cc		carry clear
	.mi		minus
	.pl		plus
	.vc		overflow clear
	.vs		overflow set

legal	relation operators
	=		equal
	<>		not equal
	>		greater than
	<		less than
	>=		greater than or equal
	<=		less than or equal
	

The keywords are searched for wherever a standard 68k mnemonic
is expected. These examples are meant to be examples of the
use of the preprocessor, so there may be logic flaws in code itself.

some example code:
strcat:
*	inputs a0,a1 ptr to strings
*	cat a1 onto a0
*	search for end of a0
	repeat
	until	(a0)+=#0.b	; end of string a0?
*	back a0 up by one
	subq.l	#1,a0

*	now tack a1 onto end of a0
	repeat
		move.b	(a1)+,(a0)+
	until =			; end of string a1?
	rts

* is <d0,d1> inside a rectangle defined by minx,miny,maxx,maxy.
* the box dimensions are from a structure pointed to by a0
*	returns d0 = 0 if <d0,d1> outside of box
*	returns d0 = 1 if <d0,d1> inside of box
inside:
	if d0>=minx(a0)
		if d0<=maxx(a0)
			if d1>=miny(a0)
				if d1<=maxy(a0)
					moveq	#1,d0	; return true
					rts
				endif
			endif
		endif
	endif
	moveq	#0,d0	; return false
	rts

spp does not handle unmatched control structures very well. So when
I write code I almost always match them up first and fill the body
in later.

********************************************************************
*                           COMERCIAL TIME                         *
********************************************************************

Redistribution of this code.
This version of the binary is free for anyone that wants to use it.
You must distribute a complete copy of this file along with the binary.
Both so people can understand how to use it as well as they will
know where to go if they want an update. It is ok for the binary and this
file to be released onto pd disks.

My name/address:
		Dale Luck
		1881 Ellwell Drive
		Milpitas, Ca. 95035
		work phone 408-262-1469
		email pyramid!oliveb!amiga!dale

I provide no telephone support accept to those that have the source.
I'm hoping that this file is good enough documentation. If I'm wrong
I'm happy to make additions/changes to improve it.

The source is available for a fee of 25$
It compiles under aztec small everything model. I have not tried
compiling under lattice but I suspect there should not be a problem.

I plan on adding more error checking so that it does not blow up
when it gets unmatched control statements. Also I want to add
a for/next construct that will use the dbxx facility of the
68k. Plus any other changes made from prompts of users besides
myself.

So if there is a second version.
The binary will become 'shareware.' Donations of 15$ will be appreciated.

For those that have purchased the source of the original version,
I will update their source free. I will be keeping a list of everyone
that is entitled to the updates.

If there are more updates after that I will probably need to get
some more money to pay for disks, mailing, etc. Maybe another 5-10$

For those that did not get the original source. The new source will
cost 30$

If you want to include this program with your other programs that you
sell you should call me.

********************************************************************
*                        end of commercial                         *
********************************************************************
