Search code examples
assemblyarmiarcortex-m

Creating a loop within an assembly macro - IAR ARM


I am trying to create a loop within an IAR Arm assembly macro but cannot figure out how to make local labels, if the macro is called more than once I get duplicate label error from the assembler. My code is as follows:

myMacro MACRO
     MOV R1, #0
label:  enter code here
     do some stuff here
     ADD R1, R1, #1         
     CMP R1, #10
     BLE label
     ENDM

Solution

  • Solved below:

    myMacro MACRO
             LOCAL label
             MOV R1, #0
        label:  enter code here
             do some stuff here
             ADD R1, R1, #1         
             CMP R1, #10
             BLE label
             ENDM