Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#166 Omit unused code and/or comment lines in listing

open
nobody
None
5
2010-01-17
2010-01-17
C. Masloch
No

I'd prefer if NASM let me configure which of these lines are omitted from the listing:

- lines in [list -] sections (currently omitted)
- lines ignored due to preprocessor conditionals
- lines which contain only comments
- empty lines

Discussion

  • > I'd prefer if NASM let me configure which of these lines are omitted from the listing:
    >
    > - lines in [list -] sections (currently omitted)

    The whole point of [list -] is to omit lines from the listing.

    > - lines ignored due to preprocessor conditionals
    > - lines which contain only comments
    > - empty lines

    These can already be achieved as follows:

    # cat z.asm
    nop
    [list -]
    hlt
    [list +]
    int3
    ; comment after whitespace but before empty line

    %if 0
    db 0
    %else
    db 1
    %endif
    # ./nasm -l z.lst z.asm
    # cat z.lst
    1 00000000 90 nop
    4 [list -]
    5 00000002 CC int3
    6 ; comment after whitespace
    but before empty line
    7
    8 %if 0
    9 db 0
    10 %else
    11 00000003 01 db 1
    12 %endif
    # ./nasm -E z.asm
    %line 1+1 z.asm
    nop
    [list -]
    hlt
    [list +]
    int3

    %line 11+1 z.asm
    db 1
    # ./nasm -E z.asm | grep -v '^$'
    %line 1+1 z.asm
    nop
    [list -]
    hlt
    [list +]
    int3
    %line 11+1 z.asm
    db 1
    # ./nasm -E z.asm | grep -v '^$' > z.asm.tmp
    # ./nasm -l z.lst -a z.asm.tmp
    # rm z.asm.tmp
    # cat z.lst
    1 00000000 90 nop
    4 [list -]
    5 00000002 CC int3
    6 00000003 01 db 1
    # hexdump z
    0000000 90 f4 cc 01

    It's trivial to wrap this process in a script or a Makefile.

     
  • C. Masloch
    C. Masloch
    2010-01-19

    > The whole point of [list -] is to omit lines from the listing.

    Yes. But you might want to include anything in the listing for some reason. NASM also allows to ignore user %warning directives, therefore I think overriding [list -] should be supported too.

    > These can already be achieved as follows:

    (Note that I had to change some macros which compute the size of areas so they use %xdefine instead of %assign to make -E work. Still displays lots of error messages but assembling the output produces the same binary as direct preprocessing and assembling of the source.)

    -E unconditionally strips all comments and lines in false conditionals. It'll also expand any macro, resulting in all macros appearing expanded in the listing. (Not putting [list -] and [list +] around .nolist macro expansions might be considered wrong. Note that [list +] would currently unconditionally enable listing again even if multipe [list -] lines appeared.) Apart from the macro expansion, this also means that blank line filtering (as you suggested to do with grep) is optional but both other types of unused lines are always removed. This is not what I meant, because I want to be able to omit (say) only lines in false conditional branches but include anything else. (Although I appreciate your effort and this listing actually is closer to what I want in this specific case.)

     
  • H. Peter Anvin
    H. Peter Anvin
    2010-01-19

    Just use a macro of your choice instead of specifying [list +] and [list -] verbatim. Problem solved.