Re: Pascal Compiler

From: Steve Judd (sjudd_at_ffd2.com)
Date: 2004-12-10 21:27:40

Hi Ruud,

> For example: 
> ...
>  var by : byte;
> ...
>  writeln(by);
> ...
> 
> The contents of by is converted to a floating point using onboard routines
> and this FP is displayed on the screen, again using onboard routines. But
> should I use these Kernal routines all the time?

I thought there was a routine for printing 16-bit ints.  Line numbers, for
example.  I also thought there was a "print signed number in .AY" routine.
But maybe it just does what you say above, I don't have it in front of me;
trivial to look up.

> Take the addition of two longints (= signed double word):
> - there is a routine to convert a longint to FP
> - there is a routine to transfer FAC to ARG
> - there is a routine to add ARG to FAC
> - there is a routine to convert a FP into a longint
> 
> But this last rountine delivers the result into the wrong order so I need my
> own routine to correct this !!! (Anyone has an idea why? Routine can be
> found at $BC9B.)

The reason is surely that float storage looks like

	1.011010110101100... * 2^exponent
          \------/\-------/ 
           byte 1  byte 2

and the four-byte mantissa is stored in order.  Conversion to/from
floating point is a matter of shifting these bytes left/right (depending
on the exponent), and the bytes are of course shifted in place.

> So I decided to make my own adder. The resulting routine needs only a few
> bytes extra then when using the Kernal routines. But I'm quite sure that it
> is much much faster.

There's no real reason to use the basic routines -- which really aren't
_kernal_ routines, per se -- for integer operations, especially addition
and subtraction.  As you point out they will be far, far slower, and may
even take up more memory.

As a practical matter, in Slang I stayed away from basic routines but had
no qualms about using kernal (E000-FFFF) routines, since switching BASIC
out is fairly common/useful but switching out the kernal is a little more
specialized.  At the moment, my only basic routine needs are floating
point.  (Years ago, someone *cough* was supposed to write a floating point
library for CMD but never did.  Bummer!)

> At this moment I'm facing more of these dilemmas: what about AND/OR/XOR-ing
> two bytes, should I use the original routines or make my own? 
> But making my own routines raises again some more questions: I have bytes,
> integers, words and longints, do I have to create routines for every type?
> The idea to solve this problem is to convert every type to longint, perform
> the needed aritmetic and to convert back again. But this comes close to
> converting them to FP. You see: dilemmas enough :(

In Slang, each variable type has three major attributes: signed/unsigned,
fixed/float, and the length in bytes.  For bitwise operations, the same
code is used for any length; the code goes something like

:loop	ApplyL LDA	;lda arg_left
	ApplyR AND	;and arg_right
	ApplySTA	;sta arg_dest
	IncArgs		;increment arg_left, arg_right, and arg_dest
	DecArgLen	;Decrement length counter
	bne :loop	;and loop if not done

This is very easy since the same code is emitted for each byte.  (As
opposed to, say, shifting left/right, since the code for the first byte is
different than the code for successive bytes, and the byte order is
reversed in one case -- but since this is Pascal this probably doesn't
matter.)

Surely something similar would work for you?

> Another subject: what is the best Basic compiler you know? I want to write
> and compile some basic and equivalent pascal programs to compare the
> resulting sizes. (And to see how they did it of course :)

I'd be happy to write something in Slang for comparison purposes too.

cu,

-Steve


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.