• @CanadaPlus
    link
    61 month ago

    I wouldn’t be able to write Rollercoaster Tycoon in assembly because keeping track of all that code in assembly files must be hell, but people pretending like you need to be some kind of wizard to write assembly code are exaggerating.

    Well, they’ve got a point for the bigger machine codes. Just the barebones specification for x86 is a doorstopper IIRC.

    From what I’ve heard, writing big stuff in assembly comes down to play-acting the compiler yourself on paper, essentially.

    • Skull giver
      link
      fedilink
      English
      101 month ago

      From what I’ve heard, writing big stuff in assembly comes down to play-acting the compiler yourself on paper, essentially.

      I think that’s true for just about any programming languages, though the program you’re “compiling” is a human understanding of what you’re trying to accomplish. Things like val bar = foo.let { it.widget?.frub() ?: FrubFactory::defaultFrub(it) } don’t come naturally to the human mind, you’re already working through the logic required before you start typing.

      As for the x86 instruction count: you don’t need to know all of them. For instance, here’s a quick graph of all of the instructions in systemctl on my system:

      With the top 15 or maybe to 25 of these instructions, you can probably write any program you can think of, and what’s missing will probably be easily found (just search for “multiply” or “divide”). You don’t need to know punpckldq to write a program.

      • @CanadaPlus
        link
        1
        edit-2
        1 month ago

        TIL. I had tried to understand it a bit, but felt lost pretty fast, and then eventually found out that’s because it’s huge. Is there a good intro to the basic instructions you’re aware of?

        By “play act the compiler” I mean a fairly elaborate system of written notes that significantly exceeds the size of the actual program. Like, it’s no wonder they started thinking about building machine compilers at that stage.

        • Skull giver
          link
          fedilink
          English
          2
          edit-2
          1 month ago

          I believe this guide can get you started pretty quickly to get the basics down. There are tons of guides online, but most of them will give you the basics (“this is how to find a prime number”) and then leave you on your own. Once you know how instructions, calling conventions, and system calls work, the rest of assembly programming is just reading documentation or Googling “how do I X in assembly”.

          What can help is using websites like godbolt.org to write simple C programs and looking at the compiled output. Look up instructions you don’t recognize and make sure you don’t enable optimizations, unless you want to deal with atrocities like VGF2P8AFFINEINVQB.

          If you don’t mind getting started with old assembly, there are also more comprehensive guides for MS-DOS and old Windows that mostly involve 16 bit and 32 bit programs programming. 64 bit programming is different (uses more registers to pass variables, floating point support is guaranteed, etc.) but there aren’t as many good books on the topic anymore now that it’s become a niche.

          I think there are quite a few guides out there for ARM these days, if you have something like a Raspberry Pi or an emulator you can also learn ARM assembly (which has fewer supported weird instructions, but also a tonne of weird stuff).

          If you want to go deep, you can also check Ben Eater’s youtube channel where he shows step by step how an 8 bit computer on a breadboard works, how instructions relate to memory, and all that. With some intuition from that, learning amd64 assembly may be a lot easier than going from normal programming languages to assembly.

          Edit: to get into understanding assembly programming, [Human Resource Machine[(https://store.steampowered.com/app/375820/Human_Resource_Machine/) will explain the concepts of assembly programming without ever overtly explaining the concepts. Plus, it’s a fun puzzle game.

      • @luciferofastora@lemmy.zip
        cake
        link
        fedilink
        11 month ago

        What language is your pseudocode example modeled after? It vaguely reminds me of some iOs App code I helped debug (Swift?) but I never really learned the language so much as eyeballed it with educated guesses, and even with the few things I double checked it has been a few years, so I have no clue what is or isn’t legal syntax anymore.

        • Skull giver
          link
          fedilink
          11 month ago

          That’s Kotlin. Mostly used for programming for the JVM, though it compiles to native code as well these days. Very interesting for cross platform app development, although I rarely do that these days.

          I think Swift has a similar syntax, but it doesn’t do some of the less obvious Kotlin tricks as far as I’m aware.

          • @luciferofastora@lemmy.zip
            cake
            link
            fedilink
            11 month ago

            I’ve heard of Kotlin in the context of Android apps, but never actually used or learned it. I did one mobile app dev project with Java in Android Studio, but never had any formal classes on it either and just learned as I went (the result was shit, but we got a decent grade for being able to evaluate the difficulties and shortcomings and point out learnings).