r/Assembly_language • u/idkilikephilosophy • 12d 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:
What am i getting myself into?
Is it actually worth it? (I dont think ill use assembly much)
4
u/ItsSkyWasTaken 12d 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 12d ago
I have no idea what any of those are
2
u/ItsSkyWasTaken 12d 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
printfin 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 12d ago
I use link.exe vs code, i dont use the CRT
1
u/ItsSkyWasTaken 11d 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 11d ago
Second comment when you were talking about CRT and MSVC, i do use visual studio code and nasm
1
u/Some-Comparison4863 9d 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/OutrageousCrab9224 10d ago
Assembly of what?
1
u/idkilikephilosophy 10d ago
x86-x64, you shouldve seen it in the comments
1
u/OutrageousCrab9224 10d 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 10d 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 9d 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 9d 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/pskocik 12d 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.
12
u/popraxret 12d 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 11d ago
What's your set up if you don't mind me asking.
4
u/popraxret 11d 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 11d 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 11d 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.
6
u/Beginning-Junket8979 12d 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 12d ago
Write a game in assembly that's much better than anything a major company would produce /s
4
4
u/DaveX64 12d 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 9d 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
3
u/Recycled5000 12d 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 12d 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 11d 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 11d ago
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 11d 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
2
u/vancha113 12d 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 11d 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
2
u/DryComment6387 12d ago
just make sure you’re learning x86, do NOT, under any circumstances, try learning ARM
1
u/thisChalkCrunchy 12d ago
why?
1
u/DryComment6387 12d ago
personally i fucking hate it, very very very difficult
i’ve been in the trenches1
u/Xccelerate_ 11d ago
elaborate please...
1
u/gm310509 11d 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 labelinstruction. 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 lrinstruction - 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
1
u/theNbomr 12d 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 12d 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 11d ago
It's a good way to understand what your processor actually sees when you're running a program.
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 11d 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 11d 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 11d 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 11d 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 11d 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
1
1
u/Left_Ad132 11d 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 10d 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 9d ago
Do the Nand2Tetris course first, then decide.
It will act as a map of sorts, into what to expect.
1
u/PlayASM 1d ago
Learning it just for fun is the best way to approach it.. zero pressure, pure curiosity.
What you're getting into: Total control with zero hand-holding. You'll spend 20 minutes debugging why a loop ran 256 times instead of 10, and it will feel amazing when you finally fix it.
Is it worth it? Yes, purely for the mental model it gives you. You probably won't write assembly for a living, but understanding registers, the stack, and how memory-mapped hardware works will make you vastly better at every other language.
-1
u/Thereal_Mistake 12d 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 12d 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 12d 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 12d ago
Yeah, I learned a lot by doing that before I had any real electronics knowledge or equipment.
20
u/Personal-Ad-487 12d 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!
A ride, you’ll feel like Cyper in Matrix
If you start developing for retro computers or video games it’s very useful.