Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

231–240 of 297 posts

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

#231

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…

It's kind of hard to get hold of a PDP-11 these days. Even getting an OS, compiler etc is not that easy. If you like the PDP-11 then you get the same qualities slightly restricted in the MSP430 and slightly enhanced in the 68000. But, really, just forget all those relics and learn either RISC-V (the best answer) or else one of the half-dozen Arm variations. I'm partial to ARM7TDMI myself for sentimental reasons doing…

I mean you can grab SIMH and trivially have a working PDP11 emulator on pretty much any system that has a C compiler.

Then just get 2.11 BSD (or V7 Unix if you're a minimalist/masochist), install it, and you're free to write/run/debug all the PDP11 assembly you want.

But I do question the value of doing this. I'm a big believer in the notion that you can't train skills by proxy, so if your goal is to become proficient in writing assembly for modern architectures, then you might as well do so by learning a modern architecture.

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

#232
post #173
post #118

I would argue that 6502 is a bad first ISA to learn if you want learn assembly. You‘ll spend most of your time fighting the quirks of this clever, but deeply flawed architecture. The idioms you learn to work around them don‘t translate to any better designed architecture that wasn‘t constrained by the tools and budget available to MOS at the time. If you want to learn a small, yet powerful instruction set with a few…

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

It's not "deeply flawed" at all, OP is being overly dramatic with that statement.

I've coded on a bunch of embedded 8-bit platforms over the decades, and 6502 is great. A, X, Y registers - it's really quite simple. It has various standard and useful addressing modes. It has pretty much the same status register that exist in modern 8-bit MCUs. There's nothing "deeply flawed" about it.

32-bit MCUs are probably a bit too complex for a beginner, 8-bit MCUs will teach a newcomer a lot about the basics of computing in an easy to learn way. It will teach them the significance of "a byte" and working with raw data that maybe you don't exactly get with 32-bit MCUs. There isn't that much to master with a 6502, it's pretty simple, but amazing things can still be done with it.

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

#233

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…

With the dmd compiler, compiling with -vasm will show the generated assembly as it compiles. It's been poo-pooed because why not use objdump or -S? But once you try it, you'll know why it's so convenient, as it just emits the assembler, and not the huge pile of boilerplate needed to make an object file. For example, I'm working on an AArch64 code generator, more specifically, generating floating point code. I have a…

You might think that the compiler was generating assembler code, and then assembling the code to binary. Nope. It generates the binary instructions directly. The compiler has a builtin disassembler for the display. This makes for a fantastic way to make sure the correct binary is generated. It has saved me an enormous amount of debugging time.

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

#234

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 register…

Definitely a bit a stretch to include the program counter, status register and stack pointer as "registers".

Of course they all are technically registers, but they really can't be used for anything useful the way the index registers and accumulator can

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

#235
post #130

Earlier quoted context omitted.

While I learned programming with 6510, I agree that 68000 instruction set was much nicer and easier to read and learn. I would also chose 68000. This said, 65XX on an early Commodore computers was extremely rewarding to use because there was no memory protection and you could write code altering video memory, mess with sprites, fonts, borders, interrupts, write self modifying code etc etc. 68000 assembly on Amiga was…

68000 assembly on Macintosh was the wild west, nothing protected at all, and it was so much fun .

When I was in college, they taught the Computer Architecture course using the 68000. Coded GUI stuff on the Mac 128k with assembler, and it was surprisingly easy, especially compared to doing anything with the 8086.

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

#236
post #173
post #118

I would argue that 6502 is a bad first ISA to learn if you want learn assembly. You‘ll spend most of your time fighting the quirks of this clever, but deeply flawed architecture. The idioms you learn to work around them don‘t translate to any better designed architecture that wasn‘t constrained by the tools and budget available to MOS at the time. If you want to learn a small, yet powerful instruction set with a few…

> 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 are wide enough to hold a pointer; and stack operations are severely limited. (This also means that writing a C compiler that targets 6502 and generates efficient code is almost impossible).

So, in idiomatic 6502 code, all variables are global; and if you need dynamically managed objects, you keep track of them using indices into statically-allocated arrays. This is difficult to scale as your programs get large and complex, because at some point you're going to waste an afternoon finding out that your "tmp7" variable in one routine is getting clobbered by another routine 5 levels deep down the call chain that also uses "tmp7" for some unrelated purpose.

It was a perfect processor for its time and its target market, but it made heavy design compromises to achieve its goals, and Moore's law quickly made those compromises obsolete.

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

#237

Earlier quoted context omitted.

I get what you're saying but I wouldn't personally call zeropage bytes _registers_, even though they are physically connected to internal ones. I treat them as a special zone of memory that has special properties. There are many of these things and just like you would start with any of the old machines you'd first take a look at the memory map to see where's what and how to use it. Registers in a traditional sense wo…

> even though they are physically connected to internal ones They're not physically connected, other than through the bus. I mean, zero page is part of DRAM.

you're right, I meant $0000 and $0001 which _are_ registers. The rest 254, yeah. Zeropage is a must on C64 at least. I don't know much about other platforms.

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

#239
post #177
post #118

I would argue that 6502 is a bad first ISA to learn if you want learn assembly. You‘ll spend most of your time fighting the quirks of this clever, but deeply flawed architecture. The idioms you learn to work around them don‘t translate to any better designed architecture that wasn‘t constrained by the tools and budget available to MOS at the time. If you want to learn a small, yet powerful instruction set with a few…

I wrote a lot of 6502 assembly once, and you spend a lot of time dealing with the 8-bittedness of the architecture. Multiplying two 16 bit numbers is a whole blob of code. That doesn't seem useful for new programmers to struggle with. The early ARM ISAs are good, as you say.

It depends on what you are trying to teach I guess. If you want to impress upon students that everything is made of bytes, that could be useful.

I don't think the 6502 would be a good fit because zero-page doesn't really translate to any useful modern concept. Quite a lot of 6502 coding is Zero-page management.

I went with 8 bit AVR as an instruction set for my silly fantasy console project. It has an in-browser editor and assembler to let people write 8 bit code. The AVR has the best 8-bit instruction set I have found, it's still not perfect (only loading constants to some registers) but definitely built with the hindsight provided by it's predecessors.

If you wanted to avoid the management of data types, I would suggest an instruction set with floating point registers. The same management of bytes into words and dwords, signed and unsigned etc. has to happen on a CPU without floating point support. It's an added complication, which you may or may not want to expose students to.

If the intent is to use Asm to teach from the point of view of "every instruction is a clearly defined action" I would use something with 32-bit ints and 32-bit floats.

If you wanted people to feel our pain, go with 6502, Z80, or PIC depending how sadistic you are.

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

#240
post #201

Earlier quoted context omitted.

Yes I'm well aware. I have a 65C02 on a breadboard. I have a 6809 on a breadboard. I've seen all Ben's videos. The *only* advantage the 6502 has is the exposed and non-multiplexed address and data busses, which you can single-step and examine with an Arduino or something. The whole setup is going to cost you the thick end of $100. But you can do that just as easily in an emulator. And meanwhile with RISC-V you can ge…

Having a large body of old software and games, written for various random platforms across 20+ years is also a killer feature.

And you'd have to spend a ton of time porting to each target system.

OTOH, the Z80 is better for this, because you can at least get CP/M up and running with a minimum of trouble.

Post reply on HN