Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

141–150 of 297 posts

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

#141
I do not know. I learned it when I was 12, but it was quite challenging for me. Pros: It is very ortagonal, has no memory-to-memory instructions

Zero page is like a having 256 generic RISC registers (a bit faster than accessing to other memory areas).

Very easy to understand how the assembly is micro-coded

Cons:

It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code.

It is a true 8bit only system and cannot manipulate 16bit word easily Steve Wozniac created a small VM just to manage 16 bit Integers (see the his Byte magazine articles).

Too much addressing mode.

So I like 6502, but I disagree a bit.

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

#142

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…

I come from a similar but different angle. Have been at 6502, 68k, z80, and some x86/64 over past few decades (mostly demo). I also wonder if this article/post was written by AI - he argues for 6502 that it has 6 registers, and thus it's simple. ANYONE who ever touched 6502 for more than a week will know you're pretty much dealing with three, and that's where the nickname of a sempahore CPU comes from (three registers).

6502 is fun and neat, especially if you want to program those machines. If you want more modern approach, it's not really all that suitable. Do what we did in the 90's then and start with MIPS if you want to follow the path of glory days or just start out with Neon. I'd even argue Z80 with all its registers and complexities is more similar to what you'll find today (far from it, but let's entertain the connection between past and present as OP does).

There's nothing inherently complicated about modern asm. Take FASM, start. It's not complicated, but it gets complex rather quickly which was and will be always true for such low level approach. Then you start macroing and sooner or later you have your own poor man's C on top.

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

#143

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…

There are roughly two ways to learn programming: top down (start with abstract concept and go down to actual implementation, e.g. SICP) and bottom up (start with the concrete low-level code and let the abstractions naturally emerge).

I studied electronics, so naturally we began with assembly (Motorola HC11). By the end of the course everyone had independently developed their macros to do things like for-loops, so it was a natural progression from there to C. By the end of the C course "C-style OOP" had also emerged naturally, which led to the next course in C++.

The downside of this approach is that it there is no gradual route from there to functional paradigms (or non-imperative in general). Also, one develops the habit of always thinking of how the language works under the hood, which can be counter, productive. E.g. when I was trying to learn Haskell, my mind was trying to understand how the interpreter worked.

Learning assembler is not just about the language, but understanding how the machine works (buses, memory-mapped peripherals, etc). In older platforms this is much simpler, so while ARM instructions can be easier to learn than the CISC instructions of the HC11, everything else is much friendlier for the beginner in the HC11.

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

#144

I'm slightly surprised that no one has suggested PDP-11 assembler as a good starting point if you're not going to learn a current instruction set. Perhaps it's because it was the first one I learnt properly but all the early miccroprocessors felt like a step backwards. I did spend a few years writing Z80 assembler but I wouldn't recommend it nowadays as it's not a very orthogonal instruction set and 6502 doesn't have…

I agree. PDP-11 is so much more pleasant, it's not even close. One could make the argument that the addressing modes are conceptually more complicated than what you'd have on a RISC, but the 6502 addressing modes are probably actually harder to understand than the PDP-11's.

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

#145
AVR-8 for the win. AVR-8 is highly orthogonal and has a whopping huge 32 register file. Devices like

https://store.arduino.cc/products/arduino-uno-rev3

are affordable and have good tooling. Memory capacity is tiny but it is fast, andthere is a lot of I/O, you can even write console programs that use the serial ports or better, programs that do physical things and also communicate over the serial ports -- in some ways AVR-8 boards are more capable than conventional computers, phones, etc. So far as I can tell, AVR-8 was the last 8-bit architecture, if it has a real weakness it is that, compared to other microcontrollers, it's a dead end because you're going to upgrade to ESP-32 or ARM if you need more.

The 6052 has more registers than the PDP-8 but just barely. Writing compilers for the 6052 is difficult because there just aren't enough registers not to mind a limited set of addressing modes. If you want to do anything interesting with the 6502 you are likely to use virtual machine [1] techniques such as Wozniak's SWEET16 or the atrocious UCSD p-System [3] or Infocom's Z Machine [4]. That kind of stuff is really fun, but so is writing straightforward AVR-8 code.

I have fond memories of the 6809 which supported really advanced software engineering techniques at the time [5] but if I had to pick a classic 8-bit architecture that is easy to find hardware for today it would have to be the Z-80, or the successor eZ80, which I think the only 24 bit micro that didn't suck (had real 24 bit index registers!) Boards are available [6]

[1] as in 'Java Virtual Machine', not 'VM/CMS'

[2] https://en.wikipedia.org/wiki/SWEET16

[3] http://pascal.hansotten.com/ucsd-p-system/

[4] https://en.wikipedia.org/wiki/Z-machine

[5] https://en.wikipedia.org/wiki/OS-9

[6] https://www.olimex.com/Products/Retro-Computers/AgonLight2/o...

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

#146

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…

This is the first time I’ve heard of this, but RISC-V not providing access to carry and overflow status seems insane. E.g. for BigNum implementations and constant-time (branchless) cryptography.

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

#147
post #114

I prefer RISCV as an starting assembly language because: it has good design, it's more intuitive, it has modern language and tool support (GCC, LLVM, Rust, etc.), and it runs on QEMU and real available hardware.

ARMv7 also meets these criteria, and is very nice to use. Available inline in BBC Basic on the Acorn Archimedes.

> Available inline in BBC Basic on the Acorn Archimedes.

The 32-bit ARM ISA, yes, but ARMv7 came much later. You're basically limited to ARM2 on the Archimedes, according to https://en.wikipedia.org/wiki/Acorn_Archimedes

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

#148

I do not know. I learned it when I was 12, but it was quite challenging for me. Pros: It is very ortagonal, has no memory-to-memory instructions Zero page is like a having 256 generic RISC registers (a bit faster than accessing to other memory areas). Very easy to understand how the assembly is micro-coded Cons: It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code. It i…

> It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code.

Sure it is. Just store your pointer in zero page, set Y to 0 and use the (ZP),Y addressing mode.

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

#149

The topic of the 6502 ISA simplicity is a pet peeve of mine, because to me it's clear that anybody thinking that such simplicity is a good thing, never progressed past a hello world. Programming anything of moderate complexity on the 6502 is hard. 8 bits are way too restrictive (e.g. screen addressing on the Commodore 64). Multiplications/divisions need to be hand-rolled. And even 16 bit sums/subtractions are simple…

> Multiplications/divisions need to be hand-rolled.

In the context of someone's first contact with assembly language, that's a good thing! Translating various multiplication and division algorithms to assembly is a great way to learn it.

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

#150
post #10

It's also a fun one to write an emulator for. There are plenty of example programs out there to test, and they draw graphics by writing bytes to a frame buffer at some offset in memory. You can read from that region in memory, interpret each byte as a color from a preset palette, and use it to display visual output / graphics. I wrote one in Swift a few years back, and then ended up developing it further into an NES…

I recently found a 6502 emulator written in Z80 assembly, which runs under CP/M:

https://github.com/davidly/a1/

The full title is " 6502 and Apple 1 emulator for 8080/Z80 CP/M 2.2 machines " which I guess gives a better idea of the (impressive) scope.

Post reply on HN