EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

Test t7233: Macro Factorial with recursion


Description
Program will create a table of 63bit integers with factorials of numbers 0 to 15. The table is built at assembly time, using macro Factorial which recursively expands itself.
See also
t7232  
Source & expected listing t7233.htm.lst
| |t7233 PROGRAM FORMAT=BIN, LISTMAP=OFF, LISTGLOBALS=OFF |[BIN] |[BIN] | |;; Define recursive macro Factorial which returns | |;; calculated value in preprocessing %variable named %Factorial. | |Factorial %MACRO Number | | %IF (%Number) <= 1 | | %Factorial %SETA 1 ; 0! and 1! calculates to 1. | | %ELSE | | ; Use not-quite-defined-yet macro Factorial to calculate | | ; factorial of immediate predecessor: | | Factorial %Number - 1 | | %Factorial %SETA (%Number) * %Factorial | | %ENDIF | |%ENDMACRO Factorial | |;; Use the macro to create table of factorials at assembly time: |0000: |FactorialTable:: |30 |n %FOR 0..15 ; The table will have 16 members. |0000: | Factorial %n ; Invoke macro to calculate n! |0000:0100000000000000 | DQ %Factorial ; Define 64bit integer value (n!). | | %ENDFOR n | | ENDPROGRAM t7233
Expected messages t7233.out
I0180 Assembling source file "t7233.htm". I0270 Assembling source "t7233". I0310 Assembling source pass 1. I0330 Assembling source pass 2 - final. I0470 Assembling program "t7233". "t7233.htm"{52} I0510 Assembling program pass 1. "t7233.htm"{52} I0510 Assembling program pass 2. "t7233.htm"{52} I0530 Assembling program pass 3 - final. "t7233.htm"{52} I0660 16bit TINY BIN file "t7233.bin" created, size=128. "t7233.htm"{72} I0650 Program "t7233" assembled in 3 passes with errorlevel 0. "t7233.htm"{72} I0750 Source "t7233" (103 lines) assembled in 2 passes with errorlevel 0. I0860 Listing file "t7233.htm.lst" created, size=1361. I0990 EuroAssembler terminated with errorlevel 0.
Expected output file t7233. bin
0000: 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ·°°°°°°°·°°°°°°°
0010: 02 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00  ·°°°°°°°·°°°°°°°
0020: 18 00 00 00 00 00 00 00 78 00 00 00 00 00 00 00  ·°°°°°°°x°°°°°°°
0030: D0 02 00 00 00 00 00 00 B0 13 00 00 00 00 00 00  ¤·°°°°°°¤·°°°°°°
0040: 80 9D 00 00 00 00 00 00 80 89 05 00 00 00 00 00  ¤¤°°°°°°¤¤·°°°°°
0050: 00 5F 37 00 00 00 00 00 00 15 61 02 00 00 00 00  °_7°°°°°°·a·°°°°
0060: 00 FC 8C 1C 00 00 00 00 00 CC 28 73 01 00 00 00  °¤¤·°°°°°¤(s·°°°
0070: 00 28 3B 4C 14 00 00 00 00 58 77 77 30 01 00 00  °(;L·°°°°Xww0·°°

▲Back to the top▲