assemblygnu-assemblerprecompiled-headers

GNU Assembly Printing Formatted Error Messages - macro substitution into quoted string for .print


I have a setup like this:

.set ERRORS, 1
.macro ERROR_SUMMARY, COUNT
    .print "\e[1;92mZ#\e[1;31m Compilation Failed with \\COUNT Error(s)\e[0m!"
.endm

ERROR_SUMMARY ERRORS

This should print: Compilation Failed with 1 Error(s).

However, instead of printing Compilation Failed with 1 Error(s) it will print Compilation Failed with ERRORS Error(s).


Solution

  • You can do it in .altmacro mode and a helper macro:

    .altmacro
    .set ERRORS, 1
    .macro ERROR_PRINT, COUNT
        .print "\e[1;92mZ#\e[1;31m Compilation Failed with \COUNT Error(s)\e[0m!"
    .endm
    .macro ERROR_SUMMARY, COUNT
        ERROR_PRINT %\COUNT
    .endm
    
    ERROR_SUMMARY ERRORS
    

    (Mind the single backslash in the .print)

    Of course if you are happy with adding the % to the invocation as ERROR_SUMMARY %ERRORS then you don't need the helper.