r/Assembly_language • • 2d ago

Countinuing from previous post:

If you hadnt heard i made a post on whether i should learn assembly, and im honestly gonna do it

Im coming from c# and im already learning some shit, its interesting to see how a computer works in the background but its unbelievably complicated, it would be nice to create a project in assembly like a OS or custom language which i only dream of in the process, (for that i shouldve probably learnt C but assembly is harder which is why i did this)

Heres some questions:

What is the optimal way for learning assembly?

What use cases did you use assembly for?

Was it worth it?

7 Upvotes

10 comments sorted by

2

u/gm310509 2d ago

What is the optimal way for learning assembly?

Start out simple - I suggest learning a simpler 8 bit CPU first such as Z-80, 6502 or even AVR. If you want to get real hardware there are kits available and Arduino is very common (the 8 bit models uses AVR MCUs).

Perhaps start out with calling a simple assembler subroutine from C and gradually move up to complete programs. If you wanted to you can have total control over the MCU in these 8 bit environments with relative ease (compared to a PC environment) and can start exploring managing hardware directly (like an operating system has to) and providing services to "applications".

2

u/theNbomr 2d ago

This exacly the advice I was going to give. Spot on.

2

u/VancouverVentilator 1d ago

Imo the optimal way is whichever motivates you most. The majority of modern home PCs are x64, with ARM being significant as well. You don't have to learn some niche 8 bit forgotten instruction set as some of the intellectuals have suggested. If it doesn't interest you, don't. I can guarantee most people who recommend some bullshit optimal path did not learn that way themselves. Good luck

1

u/Recycled5000 2d ago edited 2d ago

How should we know the optimal way for your learning style, for your current knowledge base, and for your goals for what level of understanding assembly?

That being said there are several approaches you can try:

There are teaching processors like LC-3, these have full IDEs: editor, assembler, simulator, debugger. (RISC V, also). This will teach pointers, address space, memory, registers, concepts in machine code, and assembly language. (These are free and run on common os’es with varied processors.)

Beyond that, write some C code that you understand and run it (ie single step) with a debugger in assembly mode. This will show you how common constructs like if-then(-else), loops, array indexing, etc are done.

1

u/DanKegel 2d ago

I learned it by writing tiny little programs that made noises with the speaker.

Here's an open source project I did in assembly: https://www.kegel.com/nansi/Original version: https://www.tuhs.org/Usenet/comp.sources.unix/1986-July/005881.html

The use case was: On a 4.7MHz CPU with very little RAM, the terminal emulator provided by the OS was crappy and slow, not suitable for writing real programs that used the terminal... so I wrote a better one.

It was totally worth it. I wrote a file viewer that used it, and ported MicroEmacs to use it. Plus I got a couple thousand bucks from happy shareware users!

1

u/vanderaj 2d ago

There are simpler ISAs than x86/x64 when learning the fundamentals of assembly language; you could learn to program ARM. It's a much more orthogonal ISA, and it has fewer instructions that you'll use more often. There are heaps of registers to play with, and only a few are reserved for specific purposes. You can use QEMU to emulate something with an ARM processor, whilst using your local tooling to write it. Or get a Raspberry Pi or another SBC using it, or a Mac. The only real quirk with ARM in 32-bit flavors is that, to get the most out of it, you need to think about conditional instructions, which are normal instructions that skip if certain conditions are met. This helps reduce branching and instruction pipeline holes. In 64-bit ARM, these instructions were replaced by a more general branching mechanism. I would suggest learning the 64-bit ARM version, as Linux is moving away from 32-bit support, and I can see early Pis not being supported by modern kernels at some point. Mac on Apple Silicon has always been 64 bit ARM. ARM gives you everything you want from learning assembly - how memory works, how to efficiently program in a structured way (it's really easy to program terrible assembly), and to learn how the CPU works under the hood.

Once you're comfortable with learning ARM, it's not hard to transfer that knowledge to other common ISAs, such as x86/x64 and RISC V. The biggest single difference you'll immediately notice going to x86/x64 is the limited number of registers (especially on x86 in 32 bit mode), offset registers, and the plethora of more complex instructions. Fundamentally, you don't need to know or use them all, but you should know where to look them up. Some things, like SSE SIMD vector instructions, are really important for doing high-speed maths and signal processing, but you need to read the instructions every single time.

1

u/Potential_Let_2307 1d ago

Idk personally I’m trying to implement at least a fraction of coreutils in assembly. Lots of stuff to do, great way to learn.

1

u/rileyrgham 1d ago

The fact you need to pen a post with so much nonsense in, tells me you won't be creating an OS in assembler.

My suggestion? : learn C.. it's a high level assembler.

1

u/ih-shah-may-ehl 5h ago

And it's worth noting that actual OSes are not written in assembler

1

u/IDatedSuccubi 17h ago

I don't think you need to learn any oldschool ISAs. x86-64 is not that complicated. But I would suggest to learn how computers are built first - something like a Nand to Tetris course.

Best way to learn assembly is to do some math very fast. Some simple fluid simulations, etc. That way you don't have to work with abstractions - it's all numbers, and CPUs love to work with numbers.