Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> First semester: mostly concentrated on 6502 with a full 6502 CPU emulator as the final project.

I like the principle, and the 6502 holds a special place in my heart as my introduction to machine code programming on an Apple ][ in late 1980 after I got bored with BASIC after two days .. self-taught from the ROM listing and 6502 reference in the back of the manual.

But it's absolutely the wrong ISA today.

RISC-V RV32I (or RV32E, with only 16 registers) is the right ISA today, for many reasons. It is every bit as easy to understand as 6502, if not easier. It is certainly much easier to write an emulator for than 6502 -- and I've done both. And it is at least 10x easier to write real useful programs using, especially if you're going to deal with values bigger than 8 bits, or pointers, or recursive/reentrant subroutines.

You can also cheaply buy a large and growing range of RISC-V hardware, starting from the $0.10 CH32V003 (48 MHz, 2k RAM, 16k of flash for your program) or boards with that chip for about $1, up to ESP32-C3 or RP2350 boards for a couple of bucks with a few hundred KB of RAM. Or the full Linux $5 Milk-V Duo with 1 GHz 64 bit CPU, 64 MB RAM, and SD card for the OS/programs, which you can power from the USB port on any PC and also ssh into it from the PC.

The only advantage the 6502 has now is it is one of the few chips you can still buy with exposed and non-multiplexed 16 bit address bus and 8 bit data bus, which allows you to do tricks such as hard-wiring the data bus to a NOP instruction (0xEA), and feed it a slow clock and watch the PC increment the address bus through all the NOPs.

Nice, but you can do that with an emulator too, or for that matter with a debugger talking to your microcontroller chip.



I don't disagree with you. I picked 6502 has the advantage of having so many real legacy products built on top of it.

But again, I agree it's not a great ISA (and only having 3 registers always bug me anyway), so as long as it's a real machine I think it's good. Maybe the one you talked about, or a Z80 machine, would all do the job.


Something with meaningful restrictions such as register count and RAM that you'll hit quickly when hand-coding assembler is a super IMHO useful teaching tool. 16 registers is luxurious!


The 16 registers in RV32EC [1] on the CH32V003 is not a lot using the standard ABI once you take out the zero register, return address, stack pointer, globals pointer, and thread pointer [2] you're left with 11 registers, allocated as 6 function argument / local variable registers (caller cave), 2 callee save registers, and 3 temporary registers.

Empirically you need up to 20% more instructions executed vs the 32 register RV2I, which is also similar to what Intel reports with their new "APX" x86 extension giving 32 GPRs.

The 2k RAM also concentrates the mind more so than a 6502 or Z80 with 64k RAM.

[1] you can ignore the "C" for simplicity if you want

[2] which arguably you're not going to use for that purpose so it's effectively available too, most usefully as a 3rd callee save register.


For a teaching tool, you can get the best of both worlds by simply restricting RISC-V to fewer registers. Something like: "Write this in RISC-V assembly, but only use registers 0..3, and 31 for the return address."


rv32e and rv64e have 16 registers rather than 32.

Maybe use these.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: