Compile-time calculation: Difference between revisions

(Added Rust example)
Line 10:
Discuss what limitations apply to compile-time calculations in your language.
<br><br>
 
=={{header|360 Assembly}}==
First example with the assembler equivalence pseudo instruction (EQU):
<lang 360asm>
COMPCALA CSECT
L R1,=A(FACT10) r1=10!
XDECO R1,PG
XPRNT PG,L'PG print buffer
BR R14 exit
FACT10 EQU 10*9*8*7*6*5*4*3*2*1 factorial computation
PG DS CL12
</lang>
{{out}} in the assembler listing ( 375F00 hexadecimal of 10!)
<pre>
.... 00375F00 .... FACT10 EQU 10*9*8*7*6*5*4*3*2*1 factorial computation
</pre>
{{out}} at execution time
<pre>
3628800
</pre>
Second example with an assembler macro instruction:
<lang 360asm>
MACRO
&LAB FACT &REG,&N parameters
&F SETA 1 f=1
&I SETA 1 i=1
.EA AIF (&I GT &N).EB ea: if i>n then goto eb
&F SETA &F*&I f=f*i
&I SETA &I+1 i=i+1
AGO .EA goto ea
.EB ANOP eb:
MNOTE 0,'Load &REG with &N! = &F' macro note
&LAB L &REG,=A(&F) load reg with factorial
MEND macro end
COMPCALB CSECT
USING COMPCALB,R12 base register
LR R12,R15 set base register
FACT R1,10 macro call
XDECO R1,PG
XPRNT PG,L'PG print buffer
BR R14 exit
PG DS CL12
YREGS
END COMPCALB
</lang>
{{out}} in the assembler listing
<pre>
FACT R1,10 macro call
+ MNOTE 'Load R1 with 10! = 3628800' macro note
+ L R1,=A(3628800) load reg with factorial
</pre>
 
 
=={{header|Ada}}==
1,392

edits