tech_log: ASM_CMT macro for creating comments in asm produced from C

Friday, December 12, 2008

ASM_CMT macro for creating comments in asm produced from C


C code:

//! Assembly comment
#define ASM_CMT(str) asm volatile("@ " str)

int main()
{
   int i = 5;
   int j = 0;

   ASM_CMT("This is a comment!");

   for (i=0; i<10; i++)
      j = i + 1;

   ASM_CMT("This is another comment");

   return 0;
}


Produced asm:

.file    "asm_cmt.c"
    .text
    .align    2
    .global    main
    .type    main, %function
main:
    @ args = 0, pretend = 0, frame = 8
    @ frame_needed = 1, uses_anonymous_args = 0
    mov    ip, sp
    stmfd    sp!, {fp, ip, lr, pc}
    sub    fp, ip, #4
    sub    sp, sp, #8
    mov    r3, #5
    str    r3, [fp, #-20]
    mov    r3, #0
    str    r3, [fp, #-16]
#APP
    @ This is a comment!
    mov    r3, #0
    str    r3, [fp, #-20]
    b    .L2
.L3:
    ldr    r3, [fp, #-20]
    add    r3, r3, #1
    str    r3, [fp, #-16]
    ldr    r3, [fp, #-20]
    add    r3, r3, #1
    str    r3, [fp, #-20]
.L2:
    ldr    r3, [fp, #-20]
    cmp    r3, #9
    ble    .L3
#APP
    @ This is another comment
    mov    r3, #0
    mov    r0, r3
    sub    sp, fp, #12
    ldmfd    sp, {fp, sp, pc}
    .size    main, .-main
    .ident    "GCC: (GNU) 4.2.4"


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home