如何在ARM程序集中声明一个define并使用它?

时间:2013-07-09 16:37:18

标签: gcc assembly arm

我正在尝试使用icachetest,其中有一个名为icache.s的文件包含:

#define LOOP \
        subs    r2, r2, #1             ; \ 
        mov     r0, r0                 ; \
        mov     r0, r0                 ; \ 
        mov     r0, r0                 ; \
        mov     r0, r0                 ; \
        mov     r0, r0                 ; \
        beq     end_loop               ; \
        mov     r0, r0                 ; \

我正在使用arm-eabi-as来编译这个项目,但是我收到了这个错误:

  AS     icache.S
icache.S: Assembler messages:
icache.S:16: Error: junk at end of line, first unrecognized character is `\'
icache.S:17: Error: junk at end of line, first unrecognized character is `\'
icache.S:18: Error: junk at end of line, first unrecognized character is `\'
icache.S:19: Error: junk at end of line, first unrecognized character is `\'
icache.S:20: Error: junk at end of line, first unrecognized character is `\'
icache.S:21: Error: junk at end of line, first unrecognized character is `\'
icache.S:22: Error: junk at end of line, first unrecognized character is `\'
icache.S:23: Error: junk at end of line, first unrecognized character is `\'
icache.S:52: Error: bad instruction `loop LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP'
icache.S:53: Error: bad instruction `loop LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP'
icache.S:54: Error: bad instruction `loop LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP'

1 个答案:

答案 0 :(得分:1)

其他人指出,LOOP C 宏。由于它没有参数或条件,因此很容易用gas宏替换。

.macro  LOOP
    subs    r2, r2, #1
    mov     r0, r0
    mov     r0, r0
    mov     r0, r0
    mov     r0, r0
    mov     r0, r0
    beq     end_loop
    mov     r0, r0
.endm

此后它的行为与#define相同,但需要注意的是每行只允许一个。 ARM汇编程序允许在一行上有多个操作码(据我所知)。

您可以使用.rept重复该宏。

.rept 2048
   LOOP
.endr