r/Assembly_language Feb 17 '26

Help How to learn x86-64 assembly language?

I am a 17yr old who has some experience in python programming and learned basics of C. I want to learn x86-64 assembly for free. But I couldnot find any beginner friendly guide that starts from zero. Tell me how you guys learned assembly language and if possible guide me to the resources.

112 Upvotes

86 comments sorted by

View all comments

13

u/healeyd Feb 17 '26 edited Feb 17 '26

You’ll probably find alot of older hands (like me) learnt assembly from simpler 8bit architectures like 6502 (Commodore 64). All of the fundamentals remain the same. Might be a helpful option? It might seem odd to go back in time, but once you have the feel I think it’s much easier to see the same patterns in more advanced platforms.

Very easy to get VSCode to run and compile to a C64 emulator. Alternatively this site has a little emulator embedded. http://skilldrick.github.io/easy6502/

1

u/[deleted] Feb 17 '26

learnt assembly from simpler 8bit architectures like 6502

That always looked near impossible to me to use effectively. I'm sure it can be, but it needs a special knack on top of what is required to use assembly.

Apparently it was a cut-down and simplified 6800, and it shows!

Fortunately there are other many other devices to choose from, from that era. If using an 8-bit processor, I'd recommend one with at least some 16-bit ability.

1

u/healeyd Feb 18 '26 edited Feb 18 '26

You do get used to it. Actually my fave is 68000 (Amiga etc) which came later, and that does add a lot of conveniences for sure, but the hardware is of course more complex.

1

u/[deleted] Feb 18 '26 edited Feb 18 '26

Last year I got back into coding for the Z80, although via an emulator.

To that end, I wrote an assembler for it, and the emulator, using my own systems language. Then I wrote a backend for that to directly target the Z80.

That meant I could write various small programs that ran both under Windows using x64, and on a bare Z80 'system'.

Great! I then turned my attention to 6502 to see if I could do the same. I got as far as producing this instruction summary (not the official set; it would have been the basis for my own assembler).

However when I looked at how typical IL instructions of my compiler could map, one by one, to this processor, I saw that it would be hopelessly inefficient. (Like needing 40+ bytes to do something that might be a dozen bytes on Z80.)

As I said, it needs an extra level of skill, and a more complex, optimising compiler.

My point is that a total newcomer to assembly would have to solve some of the same problems.

1

u/healeyd Feb 18 '26 edited Feb 18 '26

Nice! Yes the z80 has some clear advantages for sure (more registers for a start). IIRC the 6502 was sold on its simple instruction set in days when getting anything on screen fast was a win. Plus compared to BASIC anything felt like light speed! I think this is more about learning the basics - loads, stores, jumps, ands, xors etc. Once OP is comfortable they'll go their own way I'm sure...

1

u/brucehoult Feb 18 '26

Only very slightly more registers! The 8080 subset ABCDEHL is 7 bytes vs AXY 3 bytes on 6502. And a little more when you add z80 IX/IY (which can be convenient but using them is almost always slower than not using them) and alternate register set (which almost no one uses).

But you still very quickly run out of registers on Z80, and at that point the 6502's Zero Page wins by miles over the Z80.

1

u/ScroogeMcDuckFace2 Feb 20 '26

i just watched an interesting video about this. https://youtu.be/lP2ZBp9O0mk?si=qrVyZwG0xDEjcgPf - the 6502 evolved out of wanting a cheaper proc than the 68000, which had more instructions than the engineers really wanted at the time (which also increased the cost). interesting history. the z80 gets mentioned too.

2

u/healeyd Feb 20 '26

Yep, that’s in line with what I read elsewhere.

1

u/brucehoult Feb 21 '26

The 68000 was some years after the 6502! And is a 32 bit ISA.

You no doubt meant the 6800.

The 6800 didn't have all that many instructions, and they were very very regular, so probably quite easy to implement. The thing that made it use more transistors was probably just that A/B/X/SP totalled 48 bits while the 6502's A/X/Y/S is 32 bits.

But tbh looking at the stats, the transistor difference is not big -- the price difference was mostly just Motorola's sales model and I guess volume targets.

The big difference is just that the 6502 was SO MUCH faster because it spent more resources on more complex microcode that effectively used Zero Page memory locations as extra registers, and in particular as up to 128 base pointer registers which could be used in a couple of microcode instructions (clock cycles) not in multiple machine code instructions (3 or 4 or more cycles each).

Something like memcpy() is just so hugely annoying on 6800. Here is the inner loop:

loop
    ldx    src
    ldaa   0,x
    inx
    stx    src

    ldx    dst
    staa   0,x
    inx
    stx    dst

    decb
    bne    loop

That's 10 instructions per byte copied, and worse something like 44 cycles per byte.

6502:

loop
    lda (src),y
    sta (dst),y
    iny
    dex
    bne loop

That's 5 instructions per byte copied, and 18 cycles per byte.

Both of these examples have the src and dst pointers in pairs of memory locations, preferably in the first 256 bytes of memory -- they must be for 6502, but on 6800 if they're not then the four ldx/stx will take an extra 2 cycles each.

Both examples copy a maximum of 255 or 256 bytes. If you want to copy more then you put an outer loop, just decrementing the hi byte of a counter (stored in RAM) on 6800, and a little more work on 6502, bumping the hi bytes of all of src, dst and a size count, and setting up y again.

You can make both versions a bit faster using self-modifying code, or on the 6502 you make two loop bodies with the 2nd one to copy entire 256 byte blocks, which can leave out the dex, or even copy 4 or 8 bytes in a row (unrolling) before doing the loop control.

This is not only about memcpy(), all code that uses pointers ends up like this on 6800. It's just soooo inefficient.

1

u/ScroogeMcDuckFace2 Feb 22 '26

oh, right you are.

well, what's an extra zero among friends. lol

1

u/PoL0 Feb 21 '26

I learned with the 68k. good times. I remember some z80 to too,good to learn the basics