EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

Test t7232: Macro Factorial without recursion


Description
Program will create a table of 63bit integers with factorials of numbers 0 to 15. The table is built at assembly time.
See also
t7233  
Tested procedures
MacFind  
Source file t7232.asm
t7232 PROGRAM FORMAT=BIN, LISTMAP=OFF, LISTGLOBALS=OFF
[BIN]
; Define a non-recursive macro Factorial which returns
; calclulated value in preprocessing %variable named %Factorial:
Factorial %MACRO Number
  %N %SETA %Number
  %IF %N <= 1
    %Factorial %SETA 1     ; 0! and 1! calculates to 1.
  %ELSE
    %Factorial %SETA %N    ; Initialize returned value.
    %WHILE %N > 1
      %N %SETA %N - 1
      %Factorial %SETA %Factorial * %N
    %ENDWHILE
  %ENDIF
%ENDMACRO Factorial
;; Use the macro to create the table of factorials at assembly time:
FactorialTable::
n %FOR 0..15      ; The table will have 16 members.
    Factorial %n  ; Invoke macro to calculate n!
    DQ %Factorial ; Define 64bit integer value (n!).
  %ENDFOR n
 ENDPROGRAM t7232
Expected listing t7232.asm.lst
| |t7232 PROGRAM FORMAT=BIN, LISTMAP=OFF, LISTGLOBALS=OFF |[BIN] |[BIN] |0000: |; Define a non-recursive macro Factorial which returns |0000: |; calclulated value in preprocessing %variable named %Factorial: | |Factorial %MACRO Number | | %N %SETA %Number | | %IF %N <= 1 | | %Factorial %SETA 1 ; 0! and 1! calculates to 1. | | %ELSE | | %Factorial %SETA %N ; Initialize returned value. | | %WHILE %N > 1 | | %ENDIF | |%ENDMACRO Factorial | |;; Use the macro to create the 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 t7232
Expected messages t7232.out
I0180 Assembling source file "t7232.asm". I0270 Assembling source "t7232". I0310 Assembling source pass 1. I0330 Assembling source pass 2 - final. I0470 Assembling program "t7232". "t7232.asm"{1} I0510 Assembling program pass 1. "t7232.asm"{1} I0510 Assembling program pass 2. "t7232.asm"{1} I0530 Assembling program pass 3 - final. "t7232.asm"{1} I0660 16bit TINY BIN file "t7232.bin" created, size=128. "t7232.asm"{23} I0650 Program "t7232" assembled in 3 passes with errorlevel 0. "t7232.asm"{23} I0750 Source "t7232" (23 lines) assembled in 2 passes with errorlevel 0. I0860 Listing file "t7232.asm.lst" created, size=1255. I0990 EuroAssembler terminated with errorlevel 0.
Expected output file t7232. 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▲