Thread: Put a marker in c code and see it in assembly

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    4

    Put a marker in c code and see it in assembly

    Hey,
    I would like to know if there is a way to put somekind of a marker in c code and get the same marker in assembly when generated.
    I want to use it in order to mark the beginning and ending of some instructions and see their corresponding generated assembly code.
    I use gcc to compile.

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,194
    Sure
    Code:
    #include <stdio.h>
    int main ( ) {
      int i;
      asm("nop");
      for ( i = 0 ; i < 10 ; i++ ) {
        printf("Yes\n");
      }
      asm("nop");
      return 0;
    }
    Looks like
    Code:
    #APP
    # 4 "bar.c" 1
    	nop
    # 0 "" 2
    #NO_APP
    	movl	$0, -4(%rbp)
    	jmp	.L2
    .L3:
    	movl	$.LC0, %edi
    	call	puts
    	addl	$1, -4(%rbp)
    .L2:
    	cmpl	$9, -4(%rbp)
    	jle	.L3
    #APP
    # 8 "bar.c" 1
    	nop
    # 0 "" 2
    #NO_APP
    Just look for the #APP/#NO_APP
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    4
    Thanks Salem,
    That was very helpful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generate Assembly code and Binary code also
    By Hannibal2010 in forum C Programming
    Replies: 16
    Last Post: 07-07-2011, 05:43 AM
  2. Convert assembly>machine code, machine code>assembly
    By wenxinleong in forum C Programming
    Replies: 12
    Last Post: 06-23-2011, 10:42 PM
  3. Converting C code to DLX assembly code
    By xyz3 in forum C Programming
    Replies: 2
    Last Post: 05-17-2010, 02:01 PM
  4. JFIF Marker specs
    By abachler in forum Windows Programming
    Replies: 3
    Last Post: 05-15-2007, 10:56 AM
  5. Removing end of line marker
    By rajabadsha in forum C Programming
    Replies: 5
    Last Post: 05-13-2006, 01:24 PM