CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old March 12th, 2005, 08:03 PM
    scopium45 scopium45 is offline
    Junior Member
     
    Join Date: Sep 2004
    Posts: 13
    scopium45 is an unknown quantity at this point (<10)
    converting c code to assembly code

    does anyone know how to convert c code to assembly code?

    i really need this
    thanks
    sean
    Reply With Quote
      #2    
    Old March 13th, 2005, 06:07 AM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: converting c code to assembly code

    Quote:
    Originally Posted by scopium45
    does anyone know how to convert c code to assembly code?

    i really need this
    thanks
    sean
    Well ... this is one of the most difficult parts of writing a compiler. You must have a good sense of programming with assembler and C. You can disassembler compiled programs to look how other compilers does this job, or you can take a look at the open source compilers such as the gcc. But I can give you an example:

    Code:
    // 32bit code
    int foo ( int x, int x )
    {
        return (x + y);
    }
    Should result in:

    Code:
    foo:
       push ebp
       mov ebp, esp
       
       ; Return value expected in EAX
       mov eax, [ebp+8]    ; First parameter
       add eax, [ebp+12]  ; Second one
    
       pop ebp
    
       ret ; Somtimes it is also retf (return far)
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
      #3    
    Old March 13th, 2005, 12:04 PM
    Hobson's Avatar
    Hobson Hobson is offline
    Senior Member
     
    Join Date: Dec 2004
    Location: Poland
    Posts: 1,163
    Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)
    Re: converting c code to assembly code

    Most of compilers has option 'generate assembler source'. When you enable it and compile your files, assembly source files will be generated. However, they contain a lot of extra data, like debug info etc, and are hard to read (huh, sounds like assembler is easy to read sometimes )
    __________________
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?
    Reply With Quote
      #4    
    Old March 13th, 2005, 12:28 PM
    barrensoul's Avatar
    barrensoul barrensoul is offline
    Member
     
    Join Date: Mar 2005
    Location: Canada Alberta
    Posts: 80
    barrensoul is an unknown quantity at this point (<10)
    Re: converting c code to assembly code

    some ASM is easy to read it's rather nice being able to put ASM inside the code for C++ or C for GFX programs in certain parts (if you look at the source code for the build engine ken silverman put some of the more intensive GFX parts in pure ASM)
    __________________
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
    Reply With Quote
      #5    
    Old March 13th, 2005, 12:42 PM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: converting c code to assembly code

    Quote:
    Originally Posted by Hobson
    (huh, sounds like assembler is easy to read sometimes )
    It's easy if you are a trained ASM reader.
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
      #6    
    Old March 13th, 2005, 02:40 PM
    Hobson's Avatar
    Hobson Hobson is offline
    Senior Member
     
    Join Date: Dec 2004
    Location: Poland
    Posts: 1,163
    Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)
    Re: converting c code to assembly code

    I mean that it is not hard to read three letters long mnemonics and not so much longer arguments, which is like ~10 characters per line. But understand a story which is hidden behind those sentences is lotta harder
    __________________
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?
    Reply With Quote
      #7    
    Old March 13th, 2005, 03:35 PM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: converting c code to assembly code

    Quote:
    Originally Posted by Hobson
    I mean that it is not hard to read three letters long mnemonics and not so much longer arguments, which is like ~10 characters per line. But understand a story which is hidden behind those sentences is lotta harder
    Practice makes perfect

    Also very difficult: Writing something heavy in Assembler (like DistributionSort) and then try to read it months ago, and try to make changes in it .
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:20 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009