Compile-time calculation: Difference between revisions

Content added Content deleted
(→‎{{header|6502 Assembly}}: let cl65 provide the header)
Line 60: Line 60:
{{works with|ca65 targeting the C-64}}
{{works with|ca65 targeting the C-64}}


The ca65 cross-assembler supports computing and storing double-word (32-bit) integer values; unfortunately most 8-bit systems have no built-in support for manipulating such values. In this solution the assembler computes the actual value of 10! and stores it as a 32-bit integer; the runtime code converts that to floating point using ROM routines, dealing with the 16-bit halves of it one at a time.
The ca65 cross-assembler supports computing and storing double-word (32-bit) integer values; unfortunately most 8-bit systems have no built-in support for manipulating such values. On Commodore machines, unless you write your own arithmetic routines, you have to use floating point instead of integers for numbers that large; unfortunately the assembler doesn't support generating floating point constants. Nor is there a ROM routine to convert a 32-bit integer to a float, even though there is one to go the other way.

So in this solution the assembler computes the value of 10! and stores it as a 32-bit integer; the runtime code converts that to floating point using ROM routines, dealing with it 16 bits at a time.


<lang 6502>; Display the value of 10!, which is precomputed at assembly time
<lang 6502>; Display the value of 10!, which is precomputed at assembly time