[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic compiler



Paul Schlyter wrote:
In article <Pine.LNX.4.64.0610240911200.32311@dosius.ath.cx>,
Lyrical Nanoha  <lyricalnanoha@dosius.ath.cx> wrote:

On Tue, 24 Oct 2006, Paul Schlyter wrote:


Also, since Applesoft has no integer arithmetic (all arithmetic is
done in floating-point in Applesoft), there isn't much you can inline
when compiling Applesoft to 6502 machine code -- unless you want a
REALLY bloated Applesoft program, where each and every arithmetic
operation would take some 500 bytes of machine code!  With such
bloated code, you wouldn't be able to do much within 48K of memory.

I thought fpbasic had the % variable type (16-bit signed integer)?

-uso.


Yes, it does.  But Applesoft does execute this line:

    10  A% = B% + C%

as:

   Load integer B%, convert to floating point
   Convert integer C% to floating point, add it
   Convert the sum to integer and store in A%

Having integer variables is NOT the same as having integer arithmetic.


If you try MBASIC under Apple CP/M; you'll notice a difference.
That interpreter has integer arithmetic as distinct from floating-point
arithmetic.  Under MBASIC, the statement

     10 A% = 1% + 2%

will execute significantly faster than

     10 A% = 1.0 + 2.0

and if you compile your MBASIC program with BASIC COMPILER, the former
will execute hundreds of times faster than the latter (the former will
be compiled to inline code for an integer addition, while the latter
will compile to a subroutin calls for floating-point addition).


So Applesoft do have integer variables, but no integer arithmetic.
And the operation

     30000 * 10

won't overflow, because it is performed in floating-point arithmetic.
In MBASIC, the operation   30000% * 10%    *will* overflow !!!!




I'm surprised, on the TRS-80 which also has Microsoft basic, though a bit differently looking, does integer operations on integers (and it is an important point to use integers for speed). This is so except for division where the actual division is done in single precision. Even constants are done as integers as long as they fit.

The Microsoft basic came with the TRS-80 (Model I) Level II that came in August 1978. The original TRS-80 Microcomputer (Model I Level I) from August 1977 had a basic that was made by Tandy famous for its error messages: 3 in all WHAT?, HOW? and SORRY (means syntaxerr, outofrange and outofmemory respectively). :-)

--
Knut
(delete 'nogarbage.' for email)