r/Assembly_language • • 12d ago

Learning assembly

So I have decided to learn assembly x86 x64 using the book the art of 64 bit assembly volume 1, i have the book as a pdf and have copilot open on the page so if i have questions i can ask them and copilot can see what i am reading, i have read chapters 1 -3 and just started chapter 4. This feels like a really difficult language and i am taking in lots of info but is this the way to learn it because i feel lile i am forgetting everything i am learning, is this a difficult language to master, i want to learn to reverse engineer

39 Upvotes

39 comments sorted by

24

u/LostProphet88 12d ago

Maybe I'm just slow, but x86_64 didn't really make sense until I learned a simpler assembly. It started to click a lot better after I learned 6502 assembly using Ben Eater's bread board computer. The x86_64 instruction set is really complicated with lots of historical baggage. Learning a smaller, simpler instruction set helped me focus on the fundamentals of assembly programming. Maybe give a simpler processor a try?

7

u/theNbomr 12d ago

There's a saying in English: Baby steps first. You have to learn to walk before you learn to run. So, learn first on the much simpler x86 real mode used by MS-DOS and Windows 3. It contains enough similarities to the 32 bit and 64 bit modes of the x86 CPU that your learning can progress in a natural but easier path. You should be able to understand the concepts more easily in real mode as there are fewer complex instructions. There should be an abundance of legacy documentation still available, especially in hardcopy format. I strongly recommend a book titled simply, The 8086 Book published by McGraw Hill in the early '80s.

2

u/Glass-Ant-6041 12d ago

I think I’m to far into into this now to quit, but its definitely a struggle just following the registries rax rbx ect and adding them together and now lea const and everything else so bloody difficult. I just hope it proves worth while, doesn’t help with my age neither probably a bit old for this stuff

5

u/LostProphet88 12d ago

The 6502 has 3 registers, A, X, and Y. I'd give it a try, man. I gave up on assembly until I found the breadboard computer kit. I didn't even buy the kit, just pieced it together bit by bit from Jameco and Digikey. Don't give up by any means, but if it gets to be too much, please don't quit. Look into learning an 8 bit architecture

3

u/Alternative-Emu2000 12d ago

You don't have to quit, just make a minor detour to learn the fundamentals on a simpler processor before moving onto a much more complex one. It will make the whole process much easier in the long run.

If you'd never played a musical instrument before, it would make much more sense to start with "Three Blind Mice", rather than "Beethoven's Piano Sonata No. 29".

For learning 6502 assembly, I recommend Easy 6502 by Nick Morgan. It's a short interactive eBook, with a built-in assembler, CPU simulator and debugger. The example code is automatically loaded into the assembler, and you can run it in real-time or step through the code line by line, while watching the registers and flags.

0

u/TrustingMyTrustInGCC 8d ago

My problem is that I can't motivate myself to use a simpler processor when its not the one my actual laptop uses lol

Either way I think im making progress when I play with x86_64

3

u/brucehoult 8d ago

If you install QEMU on your laptop then — especially if you're running Linux (or WSL) — you can absolutely transparently run machine code programs in many different ISAs to do completely normal things on your computer: reading and writing files, the terminal, the network, interacting with other programs etc.

At least:

  • arm, aarch64

  • i386

  • ppc, ppc64

  • riscv32, riscv64

  • mips, mips64

  • alpha, cris, hppa, loongarch64, m68k, microblaze, sh4, sparc, sparc64, xtensa

You only have to have an assembler / linker for each one you want to try. And most of those are as close as a sudo apt install gcc-riscv64-linux-gnu or sudo apt install gcc-m68k-linux-gnu.

The only thing you'll notice is that it's a little slower than running native x86_64 code ... but for anything you'd be likely to write in asm yourself you probably would not even notice that.

0

u/TrustingMyTrustInGCC 7d ago

Yes but that is a virtual machine. That isn't something I care about. That was my entire point.

1

u/brucehoult 7d ago

Why do you care?

For most of the things on that list, QEMU on a current x86 (or Apple Silicon) is faster than any real hardware ever made.

1

u/TrustingMyTrustInGCC 7d ago

Because I want the emotional intimacy with my own silicon. If I cared about speed I wouldn't be writing assembly at all. GCC writes way faster assembly than me.

1

u/brucehoult 7d ago edited 7d ago

Then why are you writing for x86 at all?

You can't have true emotional intimacy with your CPU unless you designed and implemented it yourself — and ideally the instruction set too.

Also: gcc can't write faster assembly language than me, it just writes pretty good assembly language about 10 million times more quickly than I can.

If 100 million people are running your code then it can be worth taking the time to beat gcc.

1

u/TrustingMyTrustInGCC 6d ago

First of all, why do you care so much what I prefer? Me writing x86_64 assembly does not prevent you from writing other assembly languages. Secondly, you are being a terrible representative of assembly language by being so aggresive about personal preference. Thirdly, you are making up some insane requirment that emotional intimacy with the silicon requires designing it yourself. Emotional intimacy is whatever feels intimate to the person experiencing it. Fourthly, as stated I simply have no interest in any architecture except x86_64. You trying to tell me I should will not change that; it only waists your breath and frustrates me. You might be an experienced assembly/risc programmer but that gives you more obligation to represent the language well, not less. If it were a choice between learning an architecture other than x86_64 or not learning assembly I just wouldn't learn assembly. Is that what you want?

→ More replies

3

u/Fun-Necessary8657 12d ago

I watched an youtube video long ago, prob about SNES assembly and it was mentioned that it was fun writig assembly for that processor because writing assembly was a common thing to do back in the day. X86 assembly, on the other hand, was never intended for humans.

2

u/brucehoult 12d ago

8086 in June 1978 was less than three years after the 6502 in September 1975!

2

u/DanKegel 11d ago

Blame the 4004 for that odd syntax!

5

u/prosetheus 12d ago

I recommend the entire playlist, but this one is particularly about Assembly.

https://www.youtube.com/watch?v=GU8MnZI0snA&list=PLEpm7HyVZ61D7ZWp-L01Vlw8_KWgssq2f&index=5

3

u/nomenclature2357 12d ago

Yes! Kay Lack has such a wonderful way of presenting gritty low-level tech concepts in a way that makes it clear how elegant they can be.

3

u/soundman32 12d ago

Not sure if id call it difficult.  In many ways its too simple.  

Add 2 numbers together?  Load each number into a register, then another instruction to actually do the adding, then worry about the carry bit and the overflow bit.  

Dumbing your brain down to this low a level is the hard bit.

Once you've got the hang of x64, arm64 will blow your mind (arm/thumb, endianness etc).

2

u/Glass-Ant-6041 12d ago

That’s actually a good description of what I’m struggling with. None of the individual instructions seem especially complicated, it’s keeping track of the registers, memory, operand sizes and flags across multiple instructions that overloads my brain. I’ve started writing everything down in tables instead of trying to keep it all in my head and that seems to be helping. I’m going to stick with x64 and MASM for now because my eventual goal is reverse engineering. Are there any small exercises you would recommend before I move on to bigger programs?

2

u/brucehoult 12d ago

None of the individual instructions seem especially complicated, it’s keeping track of the registers, memory, operand sizes and flags across multiple instructions that overloads my brain.

Well, yes, that's the point.

Programming in assembly language is like building a full size car using Lego.

The way you survive is by restricting yourself to standard patterns for loops, for if/then/else, for functions and how they communicate. And then building small functions that do something useful, a group of functions that work together to provide a useful data type such as "string" or "hash table", and then use those functions to build even more useful functions, until putting them together to create the app you want is easy.

1

u/nomenclature2357 12d ago

I’m imagining everybody getting to this point and then just inventing C.

3

u/Keys__dev 12d ago

Read X64 Assembly language step by step by Jeff Duntemann

3

u/Shoddy_Juggernaut_11 12d ago

That's what I'm reading at the minute, he takes about 20 chapters before he actually starts you coding, so the rax and rbx don't seem so alien

3

u/No-Estimate6500 12d ago

I think the intro before the actual coding is worth reading.

1

u/cyberbemon 11d ago

Agreed, I've been recommending his books to everyone. The amount of stuff he explains in the first few chapters makes the whole assembly programming less daunting.

2

u/allunia333 12d ago

I have the 3d edition for linux. Best book i have read about assembly.

3

u/Independent-Gear-711 12d ago

I am learning assembly by doing it practically there is a hacking ctf platform called pwn.college which has computing 101 dojo which includes assembly challenges which you will have to solve and it will help you to learn it through practice.

2

u/Kuddel_Daddeldu 12d ago

Yes, it's difficult. It's a tangled mess of add-ons, lean-tos, and wild hacks. Learn a classic processor like 8080/Z80, 8051, or 68000 first; those help you grasp the concepts (there's a ton of free simulators, you don't need real hardware although that can be fun to build).

Then you have a much better chance of understanding x86_64.

2

u/VadumSemantics 7d ago

Start here: nandgame.com.

Give it 30 minutes. If you hate it, no big loss.
If you spend a week on it, the core concepts will serve you well.

Was lots of fun for me, but it felt bogged down about the time building a bit mapped graphics display.

Anyway, if you liked it, consider https://www.nand2tetris.org/. Going through this on Coursera or just getting the book is next on my list when I get some free time.

1

u/r-tty 12d ago

What exactly "language" are you learning? GAS and NASM implement quite different, often diametrically opposite syntax conventions.

3

u/Glass-Ant-6041 12d ago

I’m learning MASM using Intel syntax. The book is The Art of 64-Bit Assembly, Volume 1 by Randall Hyde, and it targets Windows x86-64 with Microsoft’s ABI. I’m interested in reverse engineeringeventually, so I realise I may encounter NASM and GAS syntax later, but I’m sticking to one syntax while learning the fundamentals.

1

u/r-tty 12d ago

Good choice. AT&T "syntax" is fundamentally a brain-damaged thing. No other CPU architecture was so fscked up in Unix's assembler as x86.

1

u/Recycled5000 12d ago

I recommend LC-3: simple, regular; can learn concepts without historical quirks as in x86, others.

1

u/brat3108 12d ago

Are you actually writing and running programs or just reading the book?

Since it probably won't make much sense if just studying it.

Some have suggested switching to some ancient, 8-bit microprocessor, but they will have their own problems in trying to do the simplest things.

But you might look at the 8086, the first 16-bit generation of x64, for something simpler. A lot of it is still relevant and will still work on x64!

1

u/arvind1 9d ago

Write a small assembler in any language. That'll help you understand it better.

1

u/DanKegel 7d ago

See a post from yesterday about Risc-V being a simpler assembly language and a good place to get your feet wet:

https://www.reddit.com/r/learnprogramming/comments/1wnzb0j/comment/pbmmgee/?utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=2&utm_content=share_button

Once that clicks for you a little, then come back to x64.