Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

251–260 of 297 posts

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

#251
As someone who has been teaching assembly to undergrads for many years, I have a couple of things to say about this. First of all, I agree. The 6502 is great for beginners but that is not just merit of the 6502 language and I want to explain why.

I have taught 68K, MIPS, ARM, x86, etc., and the overall good student feedback I got by teaching 6502 is mostly because of the surrounding context that comes with the CPU. The reason 6502 clicked better than other modern alternatives (MIPS, ARM, x86, etc.) was because we use it to program a real machine that is simple to understand (i.e. Nintendo Entertainment System). Rudimentary memory mapped IO, no operating system, no pipelined instructions, no delay slots, no network, no extra noise, ...it's just a simple box with a a clock inside, a CPU, some memory addresses, some helper chips, IO mapped to memory addresses, and that's pretty much it!!! So, even though I agree that the 6502 is not the simplest instruction set out there, THIS simplicity of the system helped a lot.

And about the limitations of the 6502 CPU, these limitations were also important for students to understand that these instructions have a reason to be the way they are. CPUs were designed and wired given the constraints of that time, and that reflects on how we programmed for them.

So, even thought this was mostly empirical, I have to say picking 6502 and the NES to teach beginners was successful. Once again, not really because it was the 6502, but because the 6502 forced us to go simple in terms of the sytem we were moving bits left and right.

Once students played around with the 6502 and saw NES tiles moving on the screen, then it was super cool to evolve and show them how the 68000 did things differently, and then evolve more and show how MIPS came, show how pipelining works, how to take advantage of delay slots, and being able to compare the differences of RISC and CISC. It's super simple to evolve once the basics are there.

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

#252
post #87

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…

We managed alright as 10 year old kids, as second language following up those BASIC programming comic books. For a small taste of the past, https://www.atariarchives.org/

Wow, so many memories there! Yeah, BASIC (TI-99), then Atari Basic, then Basic XL (along with reading a 6502 book), then GFA BASIC, then Megamax / Laser C, then Pascal and 68K and Ansi C at uni. RISC was part of the 4th year digital architecture/design course.

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

#253

Earlier quoted context omitted.

Great flamebait ;) what makes riscv suitable for teaching is that the ISA is trivial to map to hardware. This is because it is so regular. Students with zero experience can design simple riscv cpus in their first asm course. More experienced students can design cpus with pipelining, branch prediction, ooo execution, etc. Old ISAs from the 1980s are way more difficult.

RISC-V has been designed with the exact goal for being an ISA easy to implement in hardware, so that students will be able to do this. For this purpose, RISC-V is excellent. The RISC-V ISA has not been designed as an efficient method for encoding computer programs and even less for being easy to program in assembly language. When programming in assembly language, a complex ISA is bad, because one cannot hold in mind…

> I wonder if any of those who claim that the RISC-V ISA is simple can remember without searching the documentation how to implement the checks for integer overflow after each arithmetic operation.

I mean, I can't give you the Hacker's Delight magic numbers for expressing integer division by a constant via multiplication on AArch64 or x86-64 off the top of my head either, but that's what we have compilers for. The fact that you sometimes have to look up how to do simple things is just part of programming.

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

#254

Earlier quoted context omitted.

6502-based microcomputers like the Apple II shipped with BASIC and a 6502 monitor. The reason is that BASIC and low-level monitors can fit into tiny amounts of memory.

The Apple ][ (not plus) Integer Basic ROMs included an interactive 6502 "Mini Assembler"! That and the Applesoft ROMs also included a disassembler. https://downloads.reactivemicro.com/Users/Grant_Stockley/App...

If you had a 16 kB memory card (a.k.a "Language Card") you could overlay the ROM memory with RAM, and load the Integer Basic ROM overe the AppleSoft Basic ROM.

AppleSoft did "everything" with floating-point variables, like loops indexing into arrays. It's amazing that programs ran at usable speeds on a 1 Mhz machine.

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

#255

Earlier quoted context omitted.

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

One definition is that if it has to be saved and restored by an interrupt handler, it's a register. :)

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

#256
post #250

Earlier quoted context omitted.

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)

Sure, but the point is that you can't treat a zero page address like a register. There's a LDA, LDX, LDY, but no way to load directly to a zero page address. You have to load a real register, then store it in the ZP address.

Zero page isn't a bunch of registers because register operations by and large don't work on them directly.

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

#258

Earlier quoted context omitted.

Funny. I still remember it $FDED on the Apple // series. But printing text out like that was really slow. For fast text printing you had to write to memory locations between $400-$7FF and deal with the non continuous memory block -> screen location mapping. It was even more of a pain with 80 columns when half of the text was in the main memory and the other half was the bank switched memory.

Ouch. That sounds painful. Yeah, I usually ended up writing to screen RAM at $400. It was convenient to let the kernal manage cursor position and all that, though.

Yeah, in 40 column mode, each row was separate by 320 bytes. In 80 column mode, each even character on a line was in main memory and each odd column was in the second 64K block in extended memory.

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

#259

Earlier quoted context omitted.

6502 really has 262 registers: 256 zero page plus those standard ones mentioned. Or 260 for 6510, as zero page addresses 0 and 1 are for I/O. Practically anything non-trivial uses those zero page addresses as extra registers.

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…

One reason to consider them equivalent to registers is that the cycle time for zero page and register-based instructions is the same (2-3 cycles). The full 16-bit instructions ("absolute") take at least 1 extra cycle and often 2 if crossing a page.

Of course there is the Atari 2600 where you only have 128 of those bytes with RAM (80-FF) and the stack is set to page 0 instead of 1 (not that you'll use the stack a lot in an Atari 2600 program).

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

#260

Earlier quoted context omitted.

RISC-V has been designed with the exact goal for being an ISA easy to implement in hardware, so that students will be able to do this. For this purpose, RISC-V is excellent. The RISC-V ISA has not been designed as an efficient method for encoding computer programs and even less for being easy to program in assembly language. When programming in assembly language, a complex ISA is bad, because one cannot hold in mind…

> I wonder if any of those who claim that the RISC-V ISA is simple can remember without searching the documentation how to implement the checks for integer overflow after each arithmetic operation. I mean, I can't give you the Hacker's Delight magic numbers for expressing integer division by a constant via multiplication on AArch64 or x86-64 off the top of my head either, but that's what we have compilers for. The fa…

You don't even need a full compiler, you can just use a macro assembler if you insist on doing purely "assembly" programming.
Post reply on HN