Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

181–190 of 297 posts

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

#181
post #69

I really don't see how. When students are first exposed to computer programming, it might make sense to start with toy / compact languages that don't have any real-world use. But assembly is not the first language you're supposed to learn! It's very utilitarian and most commonly just used for debugging and reverse engineering. So why would you waste time on the assembly language of a long-obsolete platform? Plus, the…

I struggled with C until I learned to hex and assembly program on the 68HC11. Maybe I'm just a moron, but things like pointers for a complete beginner seemed so abstract and obtuse until I learned how to do indirect addressing in assembly, then suddenly it was painfully obvious why C had pointers and how they worked. Before that I just mostly used Python where it's far more abstracted away. People forget that many fe…

I have a hypothesis that to move beyond being a consumer of technology to being a producer of technology, modern education in software development should be built on building fundamentals through first principles — especially with kids and young adults. It should be analogous to how we learn counting, arithmetic, and higher level maths. One of the best features of obsolete, constrained architectures was their simplicity. Recovery for something wrong is quick and there is (generally) no permanent damage. All of this makes it much easier to understand what is happening at a lower level. Once you have a basic understanding, then you are ready for the next level of abstraction. I assume that openness and availability of IP is the biggest challenge to putting some kind of curriculum together. I would be highly interested in whether anyone has curated this into a cohesive educational approach, especially one that targets childhood development.

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

#182

Earlier quoted context omitted.

Could you say why? It doesn’t feel much like it to me at all!

ARM designers liked and had extensive experience with 6502 - it WAS their bread and butter for a long time - and this might be why the mnemonics are so similar (and carry in subtraction - that might have been for making porting easy, but I won't risk assuming that without a primary source). They obviously also studied foundational papers on RISC and understood the possibility of having a simple design (such as the 65…

Completely agree with all these points and that without the 6502 the ARM1 would not have looked like it did. One might say ARM1 was inspired by the 6502 and it prevented them going down the CISCy 68k route.

But I don't think that ARM 'ARM borrowed most of its design from 6502' or (to my mind at least) looks like a refreshed 6502. There are just too many fundamental differences:

- ARM1 was a load/store architecture / 6502 wasn't.

- 6502 had a few special purpose registers / ARM1 had loads of general purpose registers.

Plus there are lots of key innovations in ARM1 that weren't in either 6502 or RISC 1 such as conditional execution. Furber and Wilson were really quite innovative and didn't just borrrow ideas from other ISAs.

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

#183
post #5

I’ve only ever learned two assembly languages: 6502 (when I was in elementary school in the early 80s) and 370 (my senior year of high school when I had access to the UIC mainframe thanks to taking night classes there). I can roughly follow the output of godbolt on those rare occasions that I’m curious enough to bother, but the complexity of modern CPUs and computer architectures are such that I don’t know that I rea…

Same, learned as a kid. What was your motivation? Mine was wanting to make games and hitting the performance wall in basic.

Pretty much all kids want to write games.

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

#184
I program in 6502 assembly all day. It's certainly lovely as beginning assembly languages go, though it can also be limiting. The addressing modes encourage using the "Zero Page" (the memory from $0000 - $00FF) as something of an extended register set, which basically means you can have up to 128 pointers if you really want them, and lots of quick-access scratch space. If you're used to other ISAs with lots of in-CPU registers, the first thing to do is allocate about 16 bytes of "scratch" space on zeropage and use those instead. I call mine R0 - R15. Once that clicks, the rest falls into place.

Problems with the ISA become obvious the moment you want to scale your program beyond toy complexity. The stack is absurdly tiny, and trying to use it as a calling convention quickly becomes both a performance and a nesting depth bottleneck. I work around this for my larger projects by using zeropage scratch as a sortof manually-managed local scope for routines, but it requires carefully tracking which otherwise global bytes my programs are using at various nesting levels. Recursion is off the table both with this technique (difficult to manage) and with the stack (256 bytes will be exhausted very quickly). The C compilers I'm aware of work around this (slowly!) by using a separate software stack for arguments to functions.

It's pretty fun though! I'm working on a full modern indie game for the NES, which is 100% programmed in 6502 assembly for performance reasons. The existing C toolchains for the NES are either very slow (cc65) or not yet mature (llvm-mos). Most of the true complexity in the project is algorithmic stuff, like resource allocation and deciding how much work to do on a given frame. The 6502 ISA is a bit slower to write than higher level code, but it's not really a major limiter now that I've got my process down.

Here's that game if you're interested: https://zeta0134.itch.io/tactus

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

#185

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…

Came here to say that. If you must start learning with 8-bit, the 6809 is the processor of choice.

(Unless you want to really dive into "how can I work around limitations", and then you pick an F8 and pull your hair as much as you like)

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

#186
The important thing to consider is WHY you want to learn assembly language.

I learned M68K in a college class in 1995. When I saw x86 asm 2 years later it looked like a mess. But I've never needed to write asm for a job.

I'm thinking about learning 6502 because my first computer (Atari 800) and first dedicated game console (original Nintendo NES) both used the 6502 and it would be fun to write games for them when I retire.

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

#187

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?

Both reasons apply. There's probably orders of magnitude more learning material for the 6502, and the 65816 is strictly more complicated than the 6502 because it has the entire feature set of a 6502 plus modifications like register size flags and new addressing modes.

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

#188

Earlier quoted context omitted.

6502 is a better "toy" asm than the Z80, but that's not saying much. It's not even obviously better than the AVR 8-bit insn set. As far as more modern platforms, I think there is a strong case for teaching RISC-V over something like MC68k. RISC-V can be very simple and elegant (in the base integer insn set) while still being very similar to other modern architectures like ARM, Aarch-64 and MIPS. It's also available i…

Some people believe that RISC-V is simple and elegant, other people believe that RISC-V is one of the worst and ugliest instruction-set architectures that have ever been conceived. Usually the first class of people consists of people with little experience in assembly programming and the second consists of those who had experience in using multiple ISAs for assembly programming. Using RISC-V for executing programs wr…

I'm surprised RISC-V doesn't expose carry. Thanks for pointing this out. For embedded programming with AVR and ARM I often prefer ASM over C because I have access to the carry flag and I don't have to worry about C/C++ overflow undefined behavior.

I also agree the 6502 is not a simple ISA. However after learning 6502 machine code, MIPS, AVR, and ARMv6-M were all easy to learn.

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

#189
I wrote some 6502 as my final project for school (An NES game, so a specific environment) and I found it fun and extremely challenging. I'm sure there is a lot to be said for writing ASM in a modern context, but I think it's a good exercise in learning. One of the benefits you get out of working with an 8-bit processor is dealing with data bigger than 8-bits.

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

#190

Earlier quoted context omitted.

ARM designers liked and had extensive experience with 6502 - it WAS their bread and butter for a long time - and this might be why the mnemonics are so similar (and carry in subtraction - that might have been for making porting easy, but I won't risk assuming that without a primary source). They obviously also studied foundational papers on RISC and understood the possibility of having a simple design (such as the 65…

Completely agree with all these points and that without the 6502 the ARM1 would not have looked like it did. One might say ARM1 was inspired by the 6502 and it prevented them going down the CISCy 68k route. But I don't think that ARM 'ARM borrowed most of its design from 6502' or (to my mind at least) looks like a refreshed 6502. There are just too many fundamental differences: - ARM1 was a load/store architecture /…

> Furber and Wilson were really quite innovative and didn't just borrrow ideas from other ISAs.

Nobody can ever question that.

Post reply on HN