• CrazyLikeGollum@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    1 month ago

    Is there not a way to take assembly and automatically translate it to some higher level language?

    Edit: Post-post thought: I guess that would basically be one step removed from decompilation which, as I understand it, is a tedious and still fairly manual process.

    • sushibowl@feddit.nl
      link
      fedilink
      English
      arrow-up
      8
      ·
      1 month ago

      Your thought is correct. The basic problem is that higher level languages contain a lot of additional information that is lost in the compilation process.

      • Saleh@feddit.org
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 month ago

        But do we need this information then? E.g. shouldn’t it be possible to just write what the assembler is doing as a c++ code?

        E.g. high level languages also support stuff like bitwise operators and so on.

        • sushibowl@feddit.nl
          link
          fedilink
          English
          arrow-up
          5
          ·
          1 month ago

          You could, but there isn’t much benefit. The purpose of all that extra information is generally to make the program easier to understand for a human. The computer doesn’t need any of it, that’s why it’s not preserved in compilation. So it is possible to automatically translate assembly to C++, but the resulting program would not be much (if any) easier for a human to understand and work with.

          To give a bad analogy, imagine some driving directions: turn left at 9th street, enter the highway at ramp 36, go right when you’re past the burger king, etc. These are translated into physical control inputs by the driver to actually take the car to its destination. Now we could look at the driver’s physical inputs and turn that back into a written list of instructions: turn the wheel left 70 degrees, turn it right 70 degrees, push the gas for 10 seconds, and so on.

          All the street name references are now gone. There are no abstracted instructions like “enter the highway” or even “take the second left.” It would be quite difficult for a person to look at these instructions and figure out the trip’s destination. Let alone make some alterations to it because there is roadwork along the way and a detour is needed.

          • Saleh@feddit.org
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 month ago

            I get that. But the game is “finished”. there is no need for alterations. translating the assembler code into c++ in this way could serve to quickly get it in a format that is then compileable for other platforms.

            • sushibowl@feddit.nl
              link
              fedilink
              English
              arrow-up
              2
              ·
              1 month ago

              But the game is “finished”. there is no need for alterations.

              If only that was the case. But there is no chance a game built for windows 95 could run unaltered on an android phone. Things like the rendering systems, input handling, and sound output will need to be adapted to work on a new platform.

              • themoonisacheese
                link
                fedilink
                English
                arrow-up
                1
                ·
                1 month ago

                This is also exactly why Nintendo chooses to ship an emulator with the original ROM for their classic games, it’s just that much easier, especially when they don’t make the emulator either.

        • themoonisacheese
          link
          fedilink
          English
          arrow-up
          2
          ·
          1 month ago

          Take for example Haskell. It’s a functionnal, typed language. In Haskell, at compile time, the compiler analyzes all the types of all your functions and if they all match, it drops them completely. There is no type information at all left in a compiled Haskell program, because the compiler can know ahead of runtime if it is correct.