2016-11-25 50 views
1

我想註釋掉ARM彙編代碼的標籤,因爲我想使用不同的代碼,但即使我註釋掉主標籤,編譯器仍然抱怨標籤已經存在定義。如何在ARM彙編中註釋標籤

下面的代碼

.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    

這裏的錯誤接收

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

所以我能做些什麼來讓編譯器忽略註釋標籤?由於

+0

這是哪個彙編程序?凱爾? GNU彙編程序? –

+4

如果是GNU彙編程序,請使用'#'而不是';'。在GNU ARM彙編程序中,';'是語句分隔符,'#'是行註釋符 –

+0

@MichaelPetch:在ARM語法中,'@'是首選註釋字符(並且適用於所有ARM彙編程序,而不僅僅是gas)。 '#'是語法的一部分(例如,在'ADCS R1,R3,ROR#0x18'中),但在指令之前使用時,它顯然仍然用作氣體中的註釋字符。但是'add r1,r2#foo'給*錯誤:垃圾跟隨指令*。 ';'仍然是氣體語句分隔符,但這是這裏的問題。 –

回答

2

其實,我用塊註釋解決了這個問題/ **/

.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 
    ... 
*/   
1

使用GNU的ARM彙編時@字符表示單行註釋的開始:

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

+0

實際上,'#'實際上在空白或標籤之後工作,只要它在任何語句/指令之前,在氣體2.25.1。 –