0

I am trying to work with icachetest and it has a file in it named icache.s contains:

#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                 ; \

I am using arm-eabi-as to compile this project but I get this error:

  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'
0x90
  • 39,472
  • 36
  • 165
  • 245
  • 1
    You shouldn't be using `as` - just need to use `gcc` so that the preprocessor gets invoked, e.g. `gcc -Wall icache.S ...`. – Paul R Jul 09 '13 at 16:43
  • as is the assembler, clean assembly will assemble fine with as. If you are trying some mixed language thing with C code in your assembly then you need the C pre-processors before as is called by gcc. basically you dont use define in asm you use a macro. – old_timer Jul 09 '13 at 16:49
  • @PaulR will `gcc -Wall` run the as `as` well? – 0x90 Jul 09 '13 at 19:28
  • 1
    Yes, that's the whole point - if you use gcc as the driver then it takes care of preprocessing (and various other things) and passes the preprocessed asm source to `as`. – Paul R Jul 09 '13 at 20:31

1 Answers1

1

The LOOP is a C macro as others have pointed out. As it has no parameters or conditionals, it is easily replaced with a gas macro.

.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

It will behave the same as a #define after this, with the caveat that only one is allowed per line. The ARM assembler does allow multiple op-codes on a line (as far as I know).

You can use .rept to repeat the macro.

.rept 2048
   LOOP
.endr
artless noise
  • 21,212
  • 6
  • 68
  • 105
  • See similar: [Macros using gas](http://stackoverflow.com/questions/3127905/macros-using-gas) and the [GAS macro docs](http://sourceware.org/binutils/docs/as/Macro.html). – artless noise Jul 09 '13 at 18:02
  • How do I call the LOOP macro? – 0x90 Jul 09 '13 at 18:11
  • You should just need `LOOP`. You might need a '\r\n' in the source. I don't know if you can have multiple macro **calls** on a line. – artless noise Jul 09 '13 at 18:12
  • Yes you are right but is it possible to write macro run LOOP 2048 times instead of writing 2048 lines? – 0x90 Jul 09 '13 at 18:16