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

Re: Basic compiler



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 !!!!



-- 
----------------------------------------------------------------
Paul Schlyter,  Grev Turegatan 40,  SE-114 38 Stockholm,  SWEDEN
e-mail:  pausch at stockholm dot bostream dot se
WWW:     http://stjarnhimlen.se/