Translate from c to asm

Discussion in 'C Programming' started by Ronny Mandal, Dec 7, 2003.

  1. Ronny Mandal

    Ronny Mandal Guest

    Hello!

    Can anyone please provide me some resources, or maybe an algorithm / tip on
    translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    The c-routines themselves are small, trivial ones). I hvae an exam in a
    computer science course in 4 days, and I simply cannot get a grip on this
    topic.

    Any help would be highly appreciated.


    Regards,

    Ronny Mandal
     
    Ronny Mandal, Dec 7, 2003
    #1
    1. Advertising

  2. Ronny Mandal

    mhandis Guest

    Try GCC's -S argument:

    gcc -S test.c

    This should create an assembly version called test.s.

    Ronny Mandal wrote:
    > Hello!
    >
    > Can anyone please provide me some resources, or maybe an algorithm / tip on
    > translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    > The c-routines themselves are small, trivial ones). I hvae an exam in a
    > computer science course in 4 days, and I simply cannot get a grip on this
    > topic.
    >
    > Any help would be highly appreciated.
    >
    >
    > Regards,
    >
    > Ronny Mandal
    >
    >
     
    mhandis, Dec 7, 2003
    #2
    1. Advertising

  3. Ronny Mandal wrote:
    > Hello!
    >
    > Can anyone please provide me some resources, or maybe an algorithm / tip on
    > translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    > The c-routines themselves are small, trivial ones). I hvae an exam in a
    > computer science course in 4 days, and I simply cannot get a grip on this
    > topic.
    >
    > Any help would be highly appreciated.
    >
    >
    > Regards,
    >
    > Ronny Mandal
    >
    >


    Check you compiler documentation. Many have an option for creating
    assembly language listings. Also check your debugger documentation.
    Some debugger's have this capability too. You may want to see if
    they have "interwoven" capability, which is to print a C language
    statement, then followed by the assembly language. This would
    be very helpful since you can see what assembly language was created
    for each C statement.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
     
    Thomas Matthews, Dec 7, 2003
    #3
  4. Ronny Mandal

    nrk Guest

    [OT] Re: Translate from c to asm

    mhandis wrote:

    > Try GCC's -S argument:
    >
    > gcc -S test.c
    >
    > This should create an assembly version called test.s.
    >
    > Ronny Mandal wrote:
    >> Hello!
    >>
    >> Can anyone please provide me some resources, or maybe an algorithm / tip
    >> on translating from c to assembler (arbitrary assembler, but LC2 is
    >> preferred. The c-routines themselves are small, trivial ones). I hvae an
    >> exam in a computer science course in 4 days, and I simply cannot get a
    >> grip on this topic.
    >>
    >> Any help would be highly appreciated.
    >>
    >>
    >> Regards,
    >>
    >> Ronny Mandal
    >>
    >>

    On a related and totally off-topic note, does anyone have a good,
    comprehensive, online reference for the AT&T assembler syntax? I've tried
    to find one, and always come up short.

    -nrk.
     
    nrk, Dec 7, 2003
    #4
  5. Ronny Mandal

    CBFalconer Guest

    Ronny Mandal wrote:
    >
    > Can anyone please provide me some resources, or maybe an algorithm
    > / tip on translating from c to assembler (arbitrary assembler, but
    > LC2 is preferred. The c-routines themselves are small, trivial
    > ones). I hvae an exam in a computer science course in 4 days, and
    > I simply cannot get a grip on this topic.


    All you have to do is be able to code in assembly. The normal way
    of performing the transformation is via a compiler whose output
    phase was designed by someone so capable, but hand compilation is
    also acceptable. In any case you have to understand the
    destination machine.

    I suspect you are going to fail.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Dec 7, 2003
    #5
  6. Re: [OT] Re: Translate from c to asm

    nrk <> wrote:
    > mhandis wrote:
    > > Ronny Mandal wrote:
    > >> Can anyone please provide me some resources, or maybe an algorithm / tip
    > >> on translating from c to assembler

    > >
    > > Try GCC's -S argument:
    > >
    > > gcc -S test.c

    >
    > On a related and totally off-topic note, does anyone have a good,
    > comprehensive, online reference for the AT&T assembler syntax? I've tried
    > to find one, and always come up short.


    [still way OT:]

    I had the same problem, but found out that you can make gcc
    generate Intel syntax assembler:

    gcc -S -masm=intel test.c

    Regards
    --
    Irrwahn Grausewitz ()
    welcome to clc : http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
    clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
    acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~ajo/faqs/acllc-c .html
     
    Irrwahn Grausewitz, Dec 7, 2003
    #6
  7. Ronny Mandal

    Nejat AYDIN Guest

    Nejat AYDIN, Dec 7, 2003
    #7
  8. Ronny Mandal wrote:

    > Hello!
    >
    > Can anyone please provide me some resources, or maybe an algorithm / tip on
    > translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    > The c-routines themselves are small, trivial ones). I hvae an exam in a
    > computer science course in 4 days, and I simply cannot get a grip on this
    > topic.
    >


    Translating C to an assembler is very unlikely to be possible in most
    cases. The only way you could get an assembler out of a C source is if
    that source happens to be the source for an assembler. If I take the
    source for a C "hello world" program, about the only thing it can be
    translated into is a "hello world" program (usually either in machine
    language or assembly language). It can't be translated into an assembler
    any more than it could be translated into an editor or a compiler - the
    logic just isn't there.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Dec 7, 2003
    #8
  9. Ronny Mandal

    Ronny Mandal Guest

    "CBFalconer" <> wrote in message
    news:...
    > Ronny Mandal wrote:
    > >
    > > Can anyone please provide me some resources, or maybe an algorithm
    > > / tip on translating from c to assembler (arbitrary assembler, but
    > > LC2 is preferred. The c-routines themselves are small, trivial
    > > ones). I hvae an exam in a computer science course in 4 days, and
    > > I simply cannot get a grip on this topic.

    >
    > All you have to do is be able to code in assembly. The normal way
    > of performing the transformation is via a compiler whose output
    > phase was designed by someone so capable, but hand compilation is
    > also acceptable. In any case you have to understand the
    > destination machine.
    >
    > I suspect you are going to fail.


    I think you're almost right. But it is approx. 4 days remaining, so a little
    intensivereading won't hurt.
    The programs that are to be translated are only like "Hello World, etc",
    hence the chances are good indeed!

    RM
     
    Ronny Mandal, Dec 7, 2003
    #9
  10. Ronny Mandal

    Anuj Heer Guest

    Actually there are disassemblers available on the internet which can
    convert full exe codes back into assembly language. You can also find
    decompilers which can convert EXE files back to C codes. But these
    programs come with a lot of extra overhead as they convert the whole
    code on a as is where is basis to the end code and will make your life
    hell trying just to figure out where the actual usable code segment
    is. Studying hard can solve the problem in just one night. But if you
    still want those just mail me asap at .

    anuj
     
    Anuj Heer, Dec 8, 2003
    #10
  11. Ronny Mandal

    CBFalconer Guest

    Ronny Mandal wrote:
    > "CBFalconer" <> wrote in message
    > > Ronny Mandal wrote:
    > > >
    > > > Can anyone please provide me some resources, or maybe an algorithm
    > > > / tip on translating from c to assembler (arbitrary assembler, but
    > > > LC2 is preferred. The c-routines themselves are small, trivial
    > > > ones). I hvae an exam in a computer science course in 4 days, and
    > > > I simply cannot get a grip on this topic.

    > >
    > > All you have to do is be able to code in assembly. The normal way
    > > of performing the transformation is via a compiler whose output
    > > phase was designed by someone so capable, but hand compilation is
    > > also acceptable. In any case you have to understand the
    > > destination machine.
    > >
    > > I suspect you are going to fail.

    >
    > I think you're almost right. But it is approx. 4 days remaining, so
    > a little intensivereading won't hurt.
    > The programs that are to be translated are only like "Hello World,
    > etc", hence the chances are good indeed!


    Then simplify the problem. Assume you have a puts subroutine
    available, and all the program has to do is supply it the
    appropriate parameters, and then return a status. So you have to
    look up how to pass parameters, how to call a subroutine, and how
    to exit a routine with a value. You can simplify parameter
    passing to pushing onto a stack on most systems, don't know about
    yours. Others require using registers.

    You should have done all this months ago.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Dec 8, 2003
    #11
  12. (Anuj Heer) wrote in message news:<>...
    > Actually there are disassemblers available on the internet which can
    > convert full exe codes back into assembly language


    Hey there!

    You don't need to jump the gun that far.. I think most compilers have
    an assembly intermediate stage. This is definately true of gcc and
    Turbo C.

    To the OP: the assembly code generated by a compiler can tend to be
    distinguishable from hand-written assembly. There is a fairly good
    chance that if you try to hand in compiler-generated assembly, you
    will be caught out. Stripping out the comments will not do.

    It is not impossible to pick up a good bit of asm in a couple of days
    if you really put your mind to it.


    David.
     
    David M. Wilson, Dec 8, 2003
    #12
  13. Ronny Mandal

    Anuj Heer Guest

    (David M. Wilson) wrote in message news:<>...
    > (Anuj Heer) wrote in message news:<>...
    > > Actually there are disassemblers available on the internet which can
    > > convert full exe codes back into assembly language

    >
    > Hey there!
    >
    > You don't need to jump the gun that far.. I think most compilers have
    > an assembly intermediate stage. This is definately true of gcc and
    > Turbo C.
    >


    agreed totally!!!

    > To the OP: the assembly code generated by a compiler can tend to be
    > distinguishable from hand-written assembly. There is a fairly good
    > chance that if you try to hand in compiler-generated assembly, you
    > will be caught out. Stripping out the comments will not do.
    >

    yes, examiners who have been at it for quite some time can smell such
    code from miles away.

    > It is not impossible to pick up a good bit of asm in a couple of days
    > if you really put your mind to it.
    >
    >
    > David.


    that as everyone has said already would be the best approach unless
    you don't like programming which will make it the most difficult task
    of your life

    anuj
     
    Anuj Heer, Dec 8, 2003
    #13
  14. Ronny Mandal

    Mac Guest

    On Sun, 07 Dec 2003 19:39:37 +0000, Kevin Goodsell wrote:

    > Ronny Mandal wrote:
    >
    >> Hello!
    >>
    >> Can anyone please provide me some resources, or maybe an algorithm / tip on
    >> translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    >> The c-routines themselves are small, trivial ones). I hvae an exam in a
    >> computer science course in 4 days, and I simply cannot get a grip on this
    >> topic.
    >>

    >
    > Translating C to an assembler is very unlikely to be possible in most
    > cases. The only way you could get an assembler out of a C source is if
    > that source happens to be the source for an assembler. If I take the
    > source for a C "hello world" program, about the only thing it can be
    > translated into is a "hello world" program (usually either in machine
    > language or assembly language). It can't be translated into an assembler
    > any more than it could be translated into an editor or a compiler - the
    > logic just isn't there.
    >
    > -Kevin


    You are trying awfully hard to be pedantic, but the usage of the term
    "assembler" to mean "assembly language" is quite widespread. If you want
    to assert that it is unambiguously wrong, I think you have to quote an
    authoritative source of some sort.

    Mac
     
    Mac, Dec 9, 2003
    #14
  15. Mac wrote:
    > On Sun, 07 Dec 2003 19:39:37 +0000, Kevin Goodsell wrote:
    >
    > You are trying awfully hard to be pedantic, but the usage of the term
    > "assembler" to mean "assembly language" is quite widespread.


    Oh, is /that/ what he meant?

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Dec 9, 2003
    #15
  16. Ronny Mandal

    Ken Asbury Guest

    Kevin Goodsell <> wrote in message news:<ZlLAb.2996$>...
    > Ronny Mandal wrote:
    >
    > > Hello!
    > >
    > > Can anyone please provide me some resources, or maybe an algorithm / tip on
    > > translating from c to assembler (arbitrary assembler, but LC2 is preferred.
    > > The c-routines themselves are small, trivial ones). I hvae an exam in a
    > > computer science course in 4 days, and I simply cannot get a grip on this
    > > topic.
    > >

    >
    > Translating C to an assembler is very unlikely to be possible in most
    > cases. The only way you could get an assembler out of a C source is if
    > that source happens to be the source for an assembler. If I take the
    > source for a C "hello world" program, about the only thing it can be
    > translated into is a "hello world" program (usually either in machine
    > language or assembly language). It can't be translated into an assembler
    > any more than it could be translated into an editor or a compiler - the
    > logic just isn't there.
    >
    > -Kevin


    Hmmm...

    In every IDE I've seen (not an exhaustive list but certainly
    representative) one can set the simulator/emulator window to
    display C (C++) interspersed with assembly. Tag-and-drag to
    whatever editor is available, comment out the C, edit out the
    extraneous fields of line numbers and machine code, change the
    compiler-provided names to something that the assembler will
    eat and, VOILA, you have a thorough understanding of how the
    compiler works and a decent head-start on learning the specific
    assembly language of the selected micro.

    Realizing that this does not meet the OP's timeline or, perhaps,
    LC2 requirement (too lazy to google) it still provides the
    foundation for making an excellent living.

    Regards,
    Ken Asbury
     
    Ken Asbury, Dec 9, 2003
    #16
  17. Ronny Mandal

    nrk Guest

    Re: [OT] Re: Translate from c to asm

    Nejat AYDIN wrote:

    > nrk wrote:
    >>
    >> mhandis wrote:

    > [...]
    >> On a related and totally off-topic note, does anyone have a good,
    >> comprehensive, online reference for the AT&T assembler syntax? I've
    >> tried to find one, and always come up short.

    >
    > Did you try "man as", or online GNU documentation such as,
    >

    http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_chapter/as_toc.html
    >
    >

    http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_chapter/as_16.html#SEC196

    Thanks, I have perused them in the past (indeed, that's the only way I could
    make any sense out of AT&T style asm generated by gcc by default).
    However, I've always wondered if that is the best and comprehensive
    reference of the AT&T syntax... certainly the best I've managed to find
    (barring a few djgpp related web pages) in the past.

    -nrk.
     
    nrk, Dec 10, 2003
    #17
  18. Ronny Mandal

    nrk Guest

    Re: [OT] Re: Translate from c to asm

    Irrwahn Grausewitz wrote:

    > nrk <> wrote:
    >> mhandis wrote:
    >> > Ronny Mandal wrote:
    >> >> Can anyone please provide me some resources, or maybe an algorithm /
    >> >> tip on translating from c to assembler
    >> >
    >> > Try GCC's -S argument:
    >> >
    >> > gcc -S test.c

    >>
    >> On a related and totally off-topic note, does anyone have a good,
    >> comprehensive, online reference for the AT&T assembler syntax? I've
    >> tried to find one, and always come up short.

    >
    > [still way OT:]
    >
    > I had the same problem, but found out that you can make gcc
    > generate Intel syntax assembler:
    >
    > gcc -S -masm=intel test.c
    >
    > Regards


    Duh!! Never even occurred to me that gcc could be asked to generate
    assembler output in a different dialect (go on, I know how dumb I am)!!

    Now, this is good for me (confession time: I prefer the Intel syntax as I am
    more comfortable with it, and AT&T's switch of source, destination was hard
    to cope with).

    Thank you,
    -nrk.
     
    nrk, Dec 10, 2003
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Ponomarev
    Replies:
    3
    Views:
    468
    Ken Cox [Microsoft MVP]
    May 3, 2004
  2. Edwin Knoppert

    define byte asm substitute?

    Edwin Knoppert, Jan 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    506
    Edwin Knoppert
    Jan 11, 2006
  3. toddneumiller

    ASM Help

    toddneumiller, Nov 6, 2003, in forum: Java
    Replies:
    8
    Views:
    534
  4. Francesco Devittori

    ASM (vs. BCEL) - can I do this?

    Francesco Devittori, Dec 20, 2005, in forum: Java
    Replies:
    2
    Views:
    1,340
    Francesco Devittori
    Dec 21, 2005
  5. Oliver Batchelor
    Replies:
    1
    Views:
    377
    Frank Schmitt
    Jul 22, 2003
Loading...

Share This Page