How to comment label in ARM assembly

13,921

Solution 1

The @ character denotes the start of a single-line comment when using GNU's ARM assembler for 32 bit source:

The presence of a `@' anywhere on a line indicates the start of a comment that extends to the end of that line.

If a `#' appears as the first character of a line then the whole line is treated as a comment, but in this case the line could also be a logical line number directive (see Comments) or a preprocessor control command (see Preprocessing).

(source)

This is not true for 64 bit source. gas has horrible documentation for all processors (one size fits all(,so it is hard to comment on what it can and cannot do.

There may not be a way to comment out a single line in 64 bits gas. The output of the -S in gcc carefully avoids any comment lines, which is in IMO a bad sign.

This is the as I refer to on a 64 bit armbian:

 as --version
GNU assembler (GNU Binutils for Debian) 2.28

If confirmed, this could be considered a defect ("bug") and worth a bugreport.

Solution 2

Actually, I solved this problem by using block comment /**/

.section    .data                


.section    .init                
.globl     _start                

_start:                          
    b       main                 

.section    .text                
main:                            
    mov     sp, #0x8000          
    mov     r1, #1               
    mov     r2, #3               
    sub     r1, r2               
halt$:                           
    b   halt$                    

.section    .data                

/*
STARTING FROM THIS, IT IS SUPPOSED TO BE COMMENTED OUT                             
.section    .init               
.globl     _start               
    _start:                         
    b       main                

.section    .text               
main:                           
    mov     sp, #0x8000         
    bl      EnableJTAG          

    mov     r1, #0              
    mov     r2, #0              
    mov     r3, #0  ;i = 

forloop:                        
    cmp     r3, #100            
    bpl     forloopEnd          

    tst     r3, #0xAA           
    bne     elseif
    ...
*/          
Share:
13,921
Daniel
Author by

Daniel

on the way to a better programmer

Updated on June 04, 2022

Comments

  • Daniel
    Daniel almost 2 years

    I want to comment out the label of an ARM assembly code because I want to play with different codes, but even if I comment out the main label, the compiler still complains that the label is already defined.

    Here's the code

    .section    .data                
    
    
    .section    .init                
    .globl     _start                
    
    _start:                          
        b       main                 
    
    .section    .text                
    main:                            
        mov     sp, #0x8000          
        mov     r1, #1               
        mov     r2, #3               
        sub     r1, r2               
    halt$:                           
        b   halt$                    
    
    .section    .data                
    
    ; STARTING FROM THIS, IT IS SUPPOSED TO BE COMMENTED OUT                             
    ;.section    .init               
    ;.globl     _start               
    
    ;_start:                         
        ;b       main                
    
    ;.section    .text               
    ;main:                           
        ;mov     sp, #0x8000         
        ;bl      EnableJTAG          
    
        ;mov     r1, #0              
        ;mov     r2, #0              
        ;mov     r3, #0  ;i = 0      
    
    ;forloop:                        
        ;cmp     r3, #100            
        ;bpl     forloopEnd          
    
        ;tst     r3, #0xAA           
        ;bne     elseif              
    

    Here's the error received

    Error: symbol `_start' is already defined     
    Error: symbol `main' is already defined       
    Error: symbol `halt$' is already defined      
    

    So what can I do to let the compiler ignore the commented label? Thanks