Translate from c to asm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronny Mandal

    Translate from c to asm

    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

    #2
    Re: Translate from c to asm

    Try GCC's -S argument:

    gcc -S test.c

    This should create an assembly version called test.s.

    Ronny Mandal wrote:[color=blue]
    > 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
    >
    >[/color]

    Comment

    • Thomas Matthews

      #3
      Re: Translate from c to asm

      Ronny Mandal wrote:[color=blue]
      > 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
      >
      >[/color]

      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:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book
      http://www.sgi.com/tech/stl -- Standard Template Library

      Comment

      • nrk

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

        mhandis wrote:
        [color=blue]
        > Try GCC's -S argument:
        >
        > gcc -S test.c
        >
        > This should create an assembly version called test.s.
        >
        > Ronny Mandal wrote:[color=green]
        >> 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
        >>
        >>[/color][/color]
        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.

        Comment

        • CBFalconer

          #5
          Re: Translate from c to asm

          Ronny Mandal wrote:[color=blue]
          >
          > 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.[/color]

          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 (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
          Available for consulting/temporary embedded and systems.
          <http://cbfalconer.home .att.net> USE worldnet address!


          Comment

          • Irrwahn Grausewitz

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

            nrk <ram_nrk2000@de adbeef.verizon. net> wrote:[color=blue]
            > mhandis wrote:[color=green]
            > > Ronny Mandal wrote:[color=darkred]
            > >> Can anyone please provide me some resources, or maybe an algorithm / tip
            > >> on translating from c to assembler[/color]
            > >
            > > Try GCC's -S argument:
            > >
            > > gcc -S test.c[/color]
            >
            > 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.[/color]

            [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 (irrwahn33@free net.de)
            welcome to clc : http://www.angelfire.com/ms3/bchambl...me_to_clc.html
            clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
            acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...acllc-c++.html

            Comment

            • Nejat AYDIN

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

              nrk wrote:[color=blue]
              >
              > mhandis wrote:[/color]
              [...][color=blue]
              > 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.[/color]

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



              Comment

              • Kevin Goodsell

                #8
                Re: Translate from c to asm

                Ronny Mandal wrote:
                [color=blue]
                > 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.
                >[/color]

                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.

                Comment

                • Ronny Mandal

                  #9
                  Re: Translate from c to asm


                  "CBFalconer " <cbfalconer@yah oo.com> wrote in message
                  news:3FD354C6.7 132EA5C@yahoo.c om...[color=blue]
                  > Ronny Mandal wrote:[color=green]
                  > >
                  > > 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.[/color]
                  >
                  > 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.[/color]

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

                  RM


                  Comment

                  • Anuj Heer

                    #10
                    Re: Translate from c to asm

                    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 hp-anuu@vcustomer. net.

                    anuj

                    Comment

                    • CBFalconer

                      #11
                      Re: Translate from c to asm

                      Ronny Mandal wrote:[color=blue]
                      > "CBFalconer " <cbfalconer@yah oo.com> wrote in message[color=green]
                      > > Ronny Mandal wrote:[color=darkred]
                      > > >
                      > > > 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.[/color]
                      > >
                      > > 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.[/color]
                      >
                      > I think you're almost right. But it is approx. 4 days remaining, so
                      > a little intensivereadin g won't hurt.
                      > The programs that are to be translated are only like "Hello World,
                      > etc", hence the chances are good indeed![/color]

                      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 (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
                      Available for consulting/temporary embedded and systems.
                      <http://cbfalconer.home .att.net> USE worldnet address!


                      Comment

                      • David M. Wilson

                        #12
                        Re: Translate from c to asm

                        hp-anuu@vcustomer. net (Anuj Heer) wrote in message news:<868b1875. 0312071803.2a5d 3f50@posting.go ogle.com>...[color=blue]
                        > Actually there are disassemblers available on the internet which can
                        > convert full exe codes back into assembly language[/color]

                        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.

                        Comment

                        • Anuj Heer

                          #13
                          Re: Translate from c to asm

                          dw-google.com@bota nicus.net (David M. Wilson) wrote in message news:<99dce321. 0312072309.6c70 6c10@posting.go ogle.com>...[color=blue]
                          > hp-anuu@vcustomer. net (Anuj Heer) wrote in message news:<868b1875. 0312071803.2a5d 3f50@posting.go ogle.com>...[color=green]
                          > > Actually there are disassemblers available on the internet which can
                          > > convert full exe codes back into assembly language[/color]
                          >
                          > 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.
                          >[/color]

                          agreed totally!!!
                          [color=blue]
                          > 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.
                          >[/color]
                          yes, examiners who have been at it for quite some time can smell such
                          code from miles away.
                          [color=blue]
                          > 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.[/color]

                          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
                          hp-anuu@vcustomer. net

                          Comment

                          • Mac

                            #14
                            Re: Translate from c to asm

                            On Sun, 07 Dec 2003 19:39:37 +0000, Kevin Goodsell wrote:
                            [color=blue]
                            > Ronny Mandal wrote:
                            >[color=green]
                            >> 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.
                            >>[/color]
                            >
                            > 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[/color]

                            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

                            Comment

                            • Kevin Goodsell

                              #15
                              Re: Translate from c to asm

                              Mac wrote:[color=blue]
                              > 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.[/color]

                              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.

                              Comment

                              Working...