Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

241–250 of 297 posts

Re: I believe 6502 instruction set is a good first assembly language

#241
I always advocate for people to learn 6502 because it's easy and small. Not because they are going to write assembly but because they should have a basic idea of what their code is going to turn into. It doesn't matter if someone writes in Rust, Java, .Net, Python, Lua or C, it's all mov and cmp at the end of the day.

Re: I believe 6502 instruction set is a good first assembly language

#242

I'm curious what people's thoughts are on the 65816 (used by the SNES) instead of the 6502 (the NES instruction set). Is this author arguing the 6502 is preferable because it's simpler? Or because there are more/better resources for learning?

The 65816 is a pain to code for. It has what's basically a segmented memory architecture with only two segment registers: D (data bank) and P (program bank).

You can't just make a 24-bit pointer w/o doing things using the direct page, which is admittedly a bigger problem for a C compiler than an assembler.

You always have to be able to know what mode the 'A' register is in (8/16) as well as the index registers. These are separate switches. Even disassembling code on the '816 is tainted by this, because for any section of code you look at, you have to know what mode the thing is in to accurately disassemble the code.

So basically, it's a 16-bit processor, sometimes which is a bit maddening.

Re: I believe 6502 instruction set is a good first assembly language

#243
post #49

It really isn't. Biggest issue is that register width is half of pointer width, so for arbitrary pointers you at least need to make a trip through the zero page. That fact alone really obfuscates a lot of what you're trying to teach as a first stab in assembly. I say this as someone who has a whole lesson plan in 6502 asm.

IDK - I guess you are mentally modelling it wrong. Think of the zero page as a bunch of registers - that's kind of how I modelled it and it was also the hump to get over that helped someone building a 6502 compiler backend. See the slide on imaginary registers. https://llvm.org/devmtg/2022-05/slides/2022EuroLLVM-LLVM-MOS... But all that being said, 68000 or modern ARM or RISCV are also good targets. I am probably jus…

It's really not a bunch of registers though...

If you could so something like LD[$0f] #65 - then yeah, you have registers. But you can't do that sort of thing with zero page. You'd still need to do: LDA #65 STA $0f

Re: I believe 6502 instruction set is a good first assembly language

#245

I cannot agree that the simplicity of the 6502 wins over the 68000. The 68000 has more registers and wider data types: but the registers are all uniformly the same. It's really just two registers A and D, copied a bunch of times in to D0 to D7, and A0 to A7. Whatever you can do with D0 can be done with D3 and so on. Some A's are dedicated, like for a stack pointer. Simplicity of structure has to be balanced with simp…

> The best way to learn how to hack around the limitations of a tiny machine is to completely ignore them and become a seasoned software engineer Learning to hack around the limitations of a tiny machine is a good step toward becoming a seasoned software (and possibly hardware) engineer! The advantage of tiny systems is that you can understand them completely, from silicon to OS to software. The 6809 is simpler than…

I learned assembly on a 6809 (TRS-80 CoCo) platform. It was only later that I really appreciated how cool of a CPU it really was.

It’s a shame that Tandy missed the boat on including coprocessors for game support in their computers, especially that one. If they’d just included decent audio and maybe something for sprite management it would’ve been highly competitive.

Re: I believe 6502 instruction set is a good first assembly language

#248
post #71

The hairy part the 6502 instruction set is Subtract With Carry, and the confusion about how the carry flag works as a result of subtracting or comparing. SBC is implemented by adding the ones-complement (XOR FF) of the number or register. And the carry flag is backwards compared to other architectures, such as the Z80. On input, Carry Set means that you don't want an additional one subtracted, and Carry Clear means y…

Carry flag meaning "not borrow" is the same as ARM, is it not that "backwards compared to other architectures"

Re: I believe 6502 instruction set is a good first assembly language

#249
post #173

Earlier quoted context omitted.

> deeply flawed I can't even guess what you might be referring to.

The 6502 is designed to be a simple, minimal, low-cost CPU. From that perspective, it's a brilliant design, and it's fun to write small programs for. Where it becomes "deeply flawed" is if you're trying to develop large, complex programs for it, mainly because there's no way to efficiently implement pointers or local variables -- you only have 3 registers, none of which are truly "general purpose", and none of which…

>Moore's law quickly made those compromises obsolete.

Your overall argument is perfect, but I'd question the use of "quickly" since people were selling essentially 6502-based stuff for how long, 20 years at least? From the Apple II in 1977 to the SNES which was released in 1990 and still getting games in 1995, so that's 18 years of that CPU being highly relevant and worth learning.

Of course, you're 100% right that, assuming money was no object and you could buy and use whatever hardware you wanted to, it wasn't long before you could escape those compromises since the x86 and the 68000 (and probably others I don't know) brought much better architectures to those who could afford them.

Re: I believe 6502 instruction set is a good first assembly language

#250
post #49

Earlier quoted context omitted.

IDK - I guess you are mentally modelling it wrong. Think of the zero page as a bunch of registers - that's kind of how I modelled it and it was also the hump to get over that helped someone building a 6502 compiler backend. See the slide on imaginary registers. https://llvm.org/devmtg/2022-05/slides/2022EuroLLVM-LLVM-MOS... But all that being said, 68000 or modern ARM or RISCV are also good targets. I am probably jus…

It's really not a bunch of registers though... If you could so something like LD[$0f] #65 - then yeah, you have registers. But you can't do that sort of thing with zero page. You'd still need to do: LDA #65 STA $0f

You can do LDA ($0f),y

This is using a 16 byte address in zp as a ptr + y offset

For LD[$0f] #65

It's more instructions but you LDA #65 STA ($0f),Y (assume Y = 0)

Post reply on HN