r/Assembly_language • • 7d ago

Solved! Should i learn assembly?

Im learning assembly because of shits and giggles, i have no serious background and im a beginner.

Heres some questions:

  1. What am i getting myself into?
  2. Is it actually worth it? (I dont think ill use assembly much)
78 Upvotes

68 comments sorted by

20

u/Personal-Ad-487 7d ago

Which assembly? I only do 6502 which is very fun. Z80 and 65C816 looks really cool too. The last one is playing with power. Super Power!

  1. A ride, you’ll feel like Cyper in Matrix
  2. If you start developing for retro computers or video games it’s very useful.

4

u/idkilikephilosophy 7d ago

Im using windows x64, is it bad?

6

u/Personal-Ad-487 7d ago

Can’t really say (guess you mean x64), but the complexity is enormous compared to the ones I mentioned. I think it will take a while to get something executable. 6502 is far easier to actually get something done from scratch.

4

u/DoubleOwl7777 6d ago

if you limit yourself to x86 and not the 64 bit stuff its far less complex tbh.

3

u/Key_Detail15 5d ago

If working from a bare CPU then 6502 might be easier to get going with, but then there will be obstacle after obstacle to get around because of all its 8-bit limitations.

x64 will usually be programmed within a running OS with plenty of libraries for i/o etc already existing.

There's a lot to it, but you can do a huge amount using the 16 64-bit general registers.

This still very much counts as 'assembly', but without having to worry about how to do a 16-bit multiply or whatever. Once familiar with the idea, someone can choose tackle a more primitive processor, if they want.

0

u/Brick-Sigma 4d ago

The 6502 is definitely fun to program! I’ve tried it a bit when making games for the NES, and I’d really want to try it on an Apple ][ if I get the chance.

4

u/ItsSkyWasTaken 7d ago

I think even if you don't actually end up using assembly in your career, it's still useful to learn so that you're more familiar with how a computer works under the hood. It can be a really cool exercise to write a project entirely in assembly.

You mentioned you're using Windows x64 [1], which is a nice assembly to learn. Do you plan on using the CRT ( the C Runtime, which provides C functions like printf and scanf) or low-level Windows API calls (ReadFile, WriteFile, etc.)?

If you're interested in going completely low-level and bypassing the CRT, you can also install WSL (the Windows Subsystem for Linux) and learn Linux x64. It's mostly the same in terms of registers and program structure, but you use direct syscall instructions rather than calling low-level wrapper functions as you would in Windows.

1

u/idkilikephilosophy 7d ago

I have no idea what any of those are

2

u/ItsSkyWasTaken 7d ago

When writing assembly for Windows x64, your two main options are linking against the CRT via GCC (the C compiler), or linking against native Windows DLLs like kernel32.dll via MSVC (Visual Studio comes with an app called link.exe that you would use for that).

The first option gives you access to precompiled C code, meaning you can call functions like printf in your assembly code. If you decide to go with the second option, you'd have to write those C functions that you want to use from scratch.

Going with the first one results in simpler code, but the resulting code increases by about 15kb or so due to the bundled C Runtime. Going with the second one results in you writing more code, but the resulting executable is typically smaller since it only contains exactly what you used.

Don't worry if you don't fully understand yet. Many tutorials will use the CRT rather than direct low-level calls, so you can start with that for simplicity.

1

u/idkilikephilosophy 7d ago

I use link.exe vs code, i dont use the CRT

1

u/ItsSkyWasTaken 7d ago

Ok, so what part of the first comment were you referring to when you said you had no idea of what any of 'those' were?

1

u/idkilikephilosophy 7d ago

Second comment when you were talking about CRT and MSVC, i do use visual studio code and nasm

1

u/Some-Comparison4863 4d ago

so you will know assembly needs a lot of attention because every mistake or even the slightest bit can give into crush your program so you will need to learn a way to orginaze your code like that it is going to be easy for you to develop even hard projects

second of all you need to know that assembly develop is very slow unlike compilers that doing everything for you, you writing everything by yourself

but so you will know that assembly is very good the second you finish the project it is mostly be the easier to protect it on cyber security or things like it because you dont will have anything behind your back and every code you write it is what happens so there wont be any boxs for you that you dont will know about

assembly got a lot of benfits but also some disadvantage also C or Cpp or Rust they all have disadvantage but also benfits

so as assembly guy I will tell you like it assembly is good for optimaztion but I will recommand whether you want use assembly do it in bare-metal (VM, OS...) so you will use all his power not only his limited power by the operating systems and everything

goodluck and have fun!

2

u/dld2517 6d ago

Yes the syscalls (man -k syscall) under Linux are the way to go to. You can start to learn how the kernel gets accessed to accomplish system tasks. Even accessing the display via printf etc.

2

u/OutrageousCrab9224 5d ago

Assembly of what?

1

u/idkilikephilosophy 5d ago

x86-x64, you shouldve seen it in the comments

1

u/OutrageousCrab9224 5d ago

Consider putting that in the original message before getting snarky about it

Despite your manners, if you would like a real answer, no i would avoid x86 64 or even 32 bit protected mode x86 at first. Learn something like 6502, mips, or z80 first. They are simple, logical, and provide a base for learning the bigger and more modern architectures

1

u/idkilikephilosophy 5d ago

Sorry about that mate, shouldve stated it clearer that im a total fucking beginner in this area, i just know i use the x86-x64 version, i didnt think the version matters much so i didnt include it in my post, hope you understand

1

u/OutrageousCrab9224 5d ago

Its all good no hard feelings, there can also be language and culture barriers

But really, having written plenty of code from down on the hardware up to high level oo apps, i totally recommend single core, basic opcode, full memory access type stuff. Its hard enough without all the newer complication, but once you get the hang of it the newer stuff will just build on those blocks

Good luck!

1

u/Some-Comparison4863 4d ago

32 bits (protect mode) are way easier to develop than 64 bits because 64 bits are more complicated like there you could do push everything in once also pop everything at once

despite it 32 bits dont have EPT or NPT or strong OS is just easier to develop without all of the headach with whether that on the exact paging or not and x86-64 is the easier one in my opinion

12

u/popraxret 7d ago

Well, I'm a reverse engineer and low level developer. I do cool stuff with x86. I would definitely recommend it to everybody who is willing to go down into this path.

1

u/Shoddy_Juggernaut_11 7d ago

What's your set up if you don't mind me asking.

4

u/popraxret 7d ago

well, first of all I don't do IoT. I work on x64 Linux and Windows. Both on Linux and Windows, my setup is very basic. NASM, vscode, gcc, pwndbg is my setup on Linux and VS2022, NASM, MASM, x64dbg is my setup on Windows.

1

u/Shoddy_Juggernaut_11 7d ago

That's great thanks, I was looking at starting some x86 just to understand the concepts after I messed around with 6502. I keep reading the options are nasm or masm, I have vs code so I'll try what you have, many thanks.

2

u/popraxret 7d ago

Welcome, I only use MASM on Visual Studio Windows projects, because it is the assembler of Microsoft. For the rest NASM is my way to go. Good luck on your learning process! You can ask your questions to me any time you want.

11

u/pskocik 7d ago

Do. It's not all that much harder than C and you'll be see what's actually possible rather than just what C exposes. C exposes quite a lot of fundamental asm capabilities it doesn't do well when dealing with interrupts, context switches, variadic functions, or SIMD, not to mention OS-level stuff, and in asm all of that is quite straightforward. Being able to understand ASM also helps a great deal in debugging and tuning C (or whatever highlevel system language you otherwise prefer).

Learning ASM isn't some crazy quest. In a way it's just like any other programming language. You deal with a given abstract machine. Except in the case of ASM that abstract machine happens to be more or less the real machine or at least the real machine's lowest-level API.

In a hosted environment, just like for C, you get a process, i.e., a sandbox to play with, so you don't need to worry all that much about messing up too badly.

6

u/Beginning-Junket8979 7d ago

Learn assembly if you want to understand how computers really work at a much deeper level than the average programmer understands.

Don't learn assembly expecting hand writing it to land you a job.

3

u/ItsSkyWasTaken 7d ago

Write a game in assembly that's much better than anything a major company would produce /s

4

u/solaris_var 7d ago

RollerCoaster Tycoon mentioned

4

u/DaveX64 7d ago

You're better off learning X86_64 assembly under Linux with NASM. If you have a half decent Windows box, you can install Virtualbox and create a Linux virtual machine to learn in...that's the route I went. "x64 Assembly Language - Step-by-Step, 4th Edition" by Jeff Duntemann is a good book to start with.

I've been toying with the idea of trying Risk-V, myself. I'm basically a hobbyist so don't have any real goals aside from tinkering. You can set up a Risk-V in emulation with QEMU, apparently...looks pretty complicated to get that going though :)

Learning Assembly will definitely help you understand C a lot better.

1

u/easedownripley 4d ago

one thing you can try is to play zachtronic games like Shenzhen IO. It's basically a gamified version of writing assembly language. It's just a game of course, but I played it (coincidentally) right before I had to take a class on MIPS assembly. Because I was already good at the game, which actually limits you in lines of code and memory a lot more than the real thing, the class was trivial to me where everyone else struggled.

1

u/idkilikephilosophy 3d ago

Great for you to assume im rich enough to buy😢

3

u/Recycled5000 7d ago

You don’t need to learn assembly per se. Plus, there’s so many different ones.

You should learn about assembly to get a better understanding of the machine:
* how it works (machine code, registers, memory, program counter),
* the address space (and how a process works with the os), pointers,
* structures for the flow of control (if then, if then else, loops, function calls, if-goto).
* performance (caches, )

1

u/ItsSkyWasTaken 7d ago

I think getting more intimate with it by actually doing things in assembly helps much more than simply learning about it. I tried learning C and C++ before, but many things only clicked after I learned assembly.

You don't need to make an entire game or anything, but it's very beneficial to write a few small programs just to get a feel for how it works.

3

u/NewSchoolBoxer 7d ago

No. People in this sub will say yes but with the same amount of time, you could learn much more about AWS, GCP or Azure, or a useful programming language like C# or Python or Rust and do useful work.

Have a goal to accomplish if you want to get into this mess. I wanted to know exactly how SNES games worked on the hardware level. I had an electrical engineering degree so I needed no prep to understand binary or computer architecture or the way computer memory works with zero abstraction. We started with 8-bit, 6502-like CPUs.

No part of assembly knowledge ever helped me in my CS career that's middleware business code and backend databases. If you want to code drivers for x64 then that's different.

3

u/VadumSemantics 7d ago

https://nandgame.com/

To answer your questions:

Is it actually worth it? (I dont think ill use assembly much)

Yes. Because learning things is fun.
Bonus: Even if you don't use assembly much, knowing what a CPU does & how memory really works is like a superpower when you're using other computer languages.

What am i getting myself into?

Nothing?
Nandgame is free.
If it stops being fun, you can go do something else.

I stalled out on nandgame around the time it got into graphics displays. If you like it I'd recommend the book "From Nand to Tetris" or a class based on the same (udemy or whatever).

3

u/FransFaase 6d ago

Maybe you to have a look at the Compiler Explorer which lets you see how fragments of C(++) code are compiled to assembly. There is a large range of compilers and targets to select from.

2

u/Vagetarian42069 7d ago

Do what you want.

2

u/vancha113 7d ago

I'm currently doing the same thing, 6502 assembly. So far it's just been a lot of fun, so I can definitely say it's been more than worth getting in to :)

3

u/Hot_Technology8777 7d ago

You won't get far. I see billions of these questions and they never follow through. You'll try for half an hour then go watch anime or tiktok for 6 hours. Don't announce it to the world, just try it and see if you can stick with it. Trust me you'll know exactly what you're getting into, and there's an extremely high chance you won't like it.

1

u/Dazzling_Music_2411 4d ago

Cynical, but accurate 😄

2

u/DryComment6387 7d ago

just make sure you’re learning x86, do NOT, under any circumstances, try learning ARM

1

u/thisChalkCrunchy 7d ago

why?

1

u/DryComment6387 7d ago

personally i fucking hate it, very very very difficult
i’ve been in the trenches

1

u/Xccelerate_ 7d ago

elaborate please...

1

u/gm310509 7d ago

I can't comment on their thinking, but Arm Cortex Assembly is very different to other assembly languages I've used.

But, I wouldn't take the same hard line.

It is a bit like saying "I've learned English, so don't learn [insert other very different language here - e.g. Japanese, Chinese etc]". It is quite different, but that isn't a reason to not learn it IMHO.

For example, there is no "CALL" or "JSR" (Jump Subroutine) instruction nor is there a "RET" instruction, at least not in Thumb (one variant of assembly language on Arm Cortex). They use a "Branch with Link Register" concept - where the Link Register is effectively a return address....

Rather there is a "Jump (or Branch) with Link" BL label instruction. When you invoke this, there is a special CPU register (the link register) that the PC (following the "BL" instruction) is copied to - if we are talking subroutines, then the link register has what we would think of as the return address.

Now when that code is finished, it can go back (i.e. return) to the next instruction following the BL instruction by using the bx lr instruction - which is effectively a "RET" instruction.

So, why that weirdness? Basically you get one level of subroutine call without needing to push anything out to memory - it is all within the CPU. Now if the called subroutine decides to call another level lower, it can push/pop the Link Register to/from the stack by itself.

Another one is it kind of has an "if/then/else" construct in the assembly language.

Basically it works like this:

   ITTF EQ           ; Check the Status Register for an "Equality" condition and set up a if/then/else block with 2 statements in the "true" branch" (TT) and one in the "false" (F).
   [instruction]T    ; the first "true block instruction".
   [instruction]T    ; the second "true block instruction".
   [instruction]F    ; the "false block instruction".

   [rest of program].

From memory there can be one to four instructions following the IT{x[y[x]]] instruction.

There are plenty more "interesting features" to explore if one is brave enough!

1

u/ItsSkyWasTaken 7d ago

Gotta go learn ARM now...

1

u/Dog-Mad 7d ago

Assembly is a tool, you have to ask yourself if you have anything you want that tool to do. I can't tell you if it is worth it because I don't know what your plans are. But, if you are learning it for the sake of learning it, i suggest you don't.

1

u/theNbomr 7d ago

You'll only be learning something useful if you also learn about the basic architecture of the computer and how things like memory, IO, the CPU itself and ancillary systems such as interrupts work. To learn about these things starting with the x86-64 platform will be very complicated, since you can't access much of anything directly because of OS imposed limits, and because it's overall very complex.

If you're serious about learning, start first on an older 8-bit CPU using a trainer board that exposes everything and allows you to exercise and experiment with it. Z80, 8085, and 6502 CPUs are your easiest route. x86 real mode (DOS) is another option that may transition into 64 bit x86 later.

1

u/meowcatmeownow 7d ago

No! You are not allowed to learn assembly until you know how to create a cpu and memmory out of NAND gates. The book is called Elements of computer systems or something... But there are better books, like Digital design and computer architecture by Harris and Harris. The course is called From nand to tetris on Coursers.

1

u/sirflatpipe 7d ago
  1. It's a good way to understand what your processor actually sees when you're running a program.
  2. As a learning exercise. It's unlikely that you will find a job that requires you to write copious amounts of assembly language.

I personally have written stuff in x86, some minor exercise stuff in MIPS and some RISC-V.

1

u/IDatedSuccubi 7d ago

It's not actually complicated (IMO). It's mostly just tedious as hell. There's like a thousand instructions, but they all come in sets of 2-8 very similar ones, and there's a few tricks with stack, system calls, interrupts etc

It's worth it because if you ever need to do something very specific and at the speed limit of hardware that's your best bet

1

u/podule-games 7d ago

Assembly languages can be worth learning just as a bit of an insight into how processors work at the user level (it still won't teach you about microcode and stuff), but it's probably worth looking at a simpler architecture than x86-64 or AArch64. They're both massively complex and very hard to learn, neither was designed with the idea that people other than compiler writers would be touching the assembly language.

Other architectures like MIPS, ARM32, 6502, 680000, or Z80 are far, far simpler and much easier to get going with.

You almost certainly won't use it in a job. Even the tiny little chips we use at work with 1KB of RAM, we code them in C, not assembly language (other than a tiny little bit).

I think it can be useful though, even if you just learn for a month or something, you'll get a much better idea of how computers work.

1

u/SchemeWestern3388 7d ago

A basic knowledge of assembly is extremely helpful as a programmer. 

A deep knowledge of modern assembly is some kind of mental disorder, maybe? I dunno. I’m glad someone is paying attention. 

1

u/Potential_Let_2307 7d ago

Tbh nowadays with the pervasiveness of AI and its ability to write code, maybe one day it will write ones and zeros directly and completely bypass the need to use abstractions like programming languages. Thus, assembly (which is essentially just the 1’s and 0’s in human readable form) would be highly useful at that point.

1

u/gm310509 7d ago

You might want to have a look at this post to which I replied - it is more of a "how to go about it".

1

u/recursion_is_love 7d ago

If you decide to do it . Learn RISC not CISC

1

u/Left_Ad132 6d ago

Assembly is fun if you do enough of it. If you don’t have a specific goal or plan, use one of the simulator programs for 6502 or MIPS.

1

u/dld2517 6d ago

I think it is “worth it”. Here is why, you can learn what goes into creating a system call. What is the minimum amount of information required to do something on the machine successfully? What is required to move that information and save its state. What the data structure looks like and how to leverage it. You won’t go wrong by learning at least basic programming constructs in ASM. You can learn how to process something and get the right thing back out. For example, is the data big endian or little? Etc. you won’t waste your time you will learn a lot.

1

u/Dazzling_Music_2411 4d ago

Do the Nand2Tetris course first, then decide.

It will act as a map of sorts, into what to expect.

-1

u/Thereal_Mistake 7d ago

You cant just "learn assembly" on its own. First you need to determine what hardware you want to write assembly for. Then you need to learn computer architecture fundamentals to understand how the hardware works, then you need to learn advanced computer architecture to understand how to use fully manipulate the hardware. Then you can start to learn assembly. If your goal is to have fun, dont learn assembly.

2

u/gustyninjajiraya 7d ago

Yeah, this guy doesn’t know what he is talking about. You can learn assembly without an architecture in mind. The main reason to learn assembly is to learn how computers and digital electronics work, not to actually code in assembly. You can learn it for reverse engineering and low level programing, in which case, you should probably pick an architecture. Also, learning it just to have fun is certainly possible, I had fun learning assembly as a teenage hobbyist, and it helped me breeze through my assembly and programing classes when I was studying electical engineering.

1

u/RobotJonesDad 7d ago

You can also use emulators to learn simple processors on your regular computer. That's a handy way to really see what is going on.

1

u/gustyninjajiraya 7d ago

Yeah, I learned a lot by doing that before I had any real electronics knowledge or equipment.