EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

Test t8233: 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 assemble time, using macro Factorial which recursively expands itself.
See also
t8232  
Source & expected listing t8233.htm.lst
| |t8233 PROGRAM FORMAT=BIN, LISTMAP=OFF, LISTGLOBALS=OFF |[BIN] ::::Section changed. |0000: |; Define recursive macro Factorial which returns |0000: |; 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 t8233
Expected messages t8233.out
I0180 Assembling source file "t8233.htm". I0270 Assembling source "t8233". I0310 Assembling source pass 1. I0330 Assembling source pass 2 - final. I0470 Assembling program "t8233". "t8233.htm"{52} I0510 Assembling program pass 1. "t8233.htm"{52} I0510 Assembling program pass 2. "t8233.htm"{52} I0530 Assembling program pass 3 - final. "t8233.htm"{52} I0660 16bit TINY BIN file "t8233.bin" created, size=128. "t8233.htm"{72} I0650 Program "t8233" assembled in 3 passes with errorlevel 0. "t8233.htm"{72} I0750 Source "t8233" (103 lines) assembled in 2 passes with errorlevel 0. I0860 Listing file "t8233.htm.lst" created, size=1373. I0990 EuroAssembler terminated with errorlevel 0.
Expected output file t8233. 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▲