Re: Pascal Compiler

From: Steve Judd (sjudd_at_ffd2.com)
Date: 2004-12-12 16:43:41

Hi Spiro,

I don't think we disagree; a potential source of confusion here is which
code we're talking about.  There is the code emitted by a compiler, and
the code, in the compiler, which emits or generates that code.

So, for bitwise operations, the _emitted code_ should look like:

	lda arg1
	and arg2
	sta dest
	lda arg1+1
	and arg2+1
	...

where the same thing is repeated depending only on the length.  The _code
to emit_ this code can go something like

	emit "lda argl"
	emit "and argr"
	emit "sta dest"
	increment args
	decrement argument length
	if nonzero then loop

I thought Ruud was talking about how to write the compiler routine to emit
code, so all I was trying to say is that it's easy to write a generic
integer routine that handles different type sizes -- no need to e.g.
convert to 4-byte int, perform the opertion, and convert back, or write
separate routines for each type size (one routine for bytes, another for
ints, another for...), or ....

As to shifts, the first instruction is different:

	asl argl
	rol argl+1
	rol argl+2
	...

so there's just a little more work in writing the loop to generate this
code.  Shifts in the opposite direction start with the highest byte first,
which is a little more work.

You could of course CLC first and then rol each byte, but that seems like
a poor, and unnecessary, alternative.

Incidentally, in Slang there's another level: "the code which generates
the compiler code which emits the code" :)

> Of course it is arguable, but in general, I would prefer speed over
> size.

While I agree in general, there are a surprising (to me anyways) number of
exceptions.

cu,

-Steve


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.