by progmetaldev · 1y ago · 0 comments
I feel like learning modern assembly would be more useful, but maybe 6502 assembly is far easier to pick up? The first language I learned was Atari BASIC around 1991, and it was enough to get me to keep on moving to better languages and more powerful CPUs, but I wonder where I would have ended up if I learned assembly either before or after Atari BASIC. I try to keep up with technology, and have read quite a bit on different assembly dialects. I still haven't learned an assembly that I can program in, and I suppose it's because there are so many other high-level languages now and I feel like I need to keep up to what is used in "industry" rather than what is more obscure (but might help in debugging).
And as it turned out, I didn't have any problems adapting to the expanded PPC ISA. Being on the 6502 already taught me how to chop problems down into tiny bits and now the bits didn't have to be so tiny. I certainly wasn't trying to do 8-bit chained adds for bigger quantities anymore; it didn't make sense to when I had 32-bit registers and an FPU.
In so many of these years I had not learned C. I went from assembly to scripting languages, and was a very early adopter of Javascript since the same month it first came out. Only in the last 10 years have I learned C, and it was so easy! After learning Assembly and Javascript, C was right in the middle.
I've programmed in over a dozen languages through the years, but I'm really happy with Assembly, C, and Javascript as my stack depending on the project.
I spent my teenage years grabbing cracks and texts from BBS', and enjoyed the whole scene. It's really what sparked my interest into writing software, and I always wished I had learned some lower-level skills beyond running a debugger and poking at memory. I felt like if I knew Assembly, I could get into deeper debugging (cracking was initially my "exciting" topic to cover, but now I feel like it would just be understanding memory better when I run into a strange error).
We have found that when needed, students pick up the newer/more advanced assembly languages (e.g. ARM, x86) fairly well, so we believe the early and universal introduction to MIPS does provide benefits.
Many of the instructions have similar mnemonics, such as the conditional branch instructions (BEQ, BNE, BCC, BCS, BMI, BPL, BVS, BVC), as well as the arithmetic instructions like ADC, SBC, EOR.
Not really (perhaps leaving mnemonics aside). The 6502 has little in common with the first ARM. The ARM's designers liked the simplicity and speed of the 6502 and it was their favourite 8-bit ISA. And a visit to the Western Design Center convinced them to design their own CPU.
However, the early RISC papers were the biggest influence on the design of the ARM. There is even a clue in the name 'Acorn RISC Machine'.
The simplicity of RISC-V is illusory. Because it lacks many features of normal ISAs, like ARM or Intel/AMD x86-64, writing programs that are both efficient and robust, i.e. which handle safely any errors, is quite difficult in assembly language.
For a simpler programming in assembly language it is hard to beat DEC PDP-11 and Motorola 68000 derivatives.
However those are no longer directly useful in practice. For something useful, the best would be to learn assembly programming using a development board for some Cortex-M microcontroller, preferably a less ancient core, e.g. with Cortex-M23 or Cortex-M33 or Cortex-M55 or Cortex-M85, i.e. cores implementing the Armv8-M ISA (the latter 2 also implement the Helium vector extension).
Probably some development board with a microcontroller using Cortex-M33 would be the easiest to find and it should cost no more than $20 to $30. I would not recommend for learning today any of the development boards with obsolete cores, like Cortex-M0+, Cortex-M3, Cortex-M4 or Cortex-M7, even if those boards can be found e.g. at $10 or even less.
Such a development board can be connected to any PC with a USB cable. All the development tools are free (there are paid alternatives, but those are not better than the free GNU tools).
You can compile or assemble your program on the PC, then load and run it on the development board. You can have a serial console window connecting to your program, by using a serial port on the development board and a USB serial interface. All such development boards have LEDs and various connectors for peripherals, allowing you to see what your program does.
I think that learning to program in assembly such an Armv8-M microcontroller is more useful than learning something like 6502. Armv8-M is less quirky than 6502 or RISC-V and it is something that you can use for implementing some useful home device or even professionally.
Otherwise, the best is to learn the assembly language of your personal computer, e.g. x86-64 or Aarch64, but that is much more difficult than starting with a microcontroller development board from ST (e.g. a cheap STM32 Nucleo variant), NXP, Infineon, Renesas, Microchip, etc.
The Pi Pico 2 RP2350 has dual Cortex-M33 cores (and RISC-V), and costs US$5.
Do you have some examples of this?
There are absolutely no reasons for omitting these essential features, because their hardware implementation is many times simpler and cheaper than either the software workarounds for their absence or than the hardware workarounds that can be implemented in other parts of the CPU core, e.g. instruction fusion.
6502 is much more similar to a normal CPU than RISC-V, because it has both integer overflow detection and indexed addressing.
While I believe that other ISAs are better than 6502 for learning assembly language for the first time, I consider 6502 as a much better choice than RISC-V.
RISC-V could be used for teaching if that would be done in the right way, i.e. by showing how to implement with the existing RISC-V instructions everything that is missing in RISC-V. In that case the students would still learn how to write real programs instead of toy didactic programs.
However I have not seen any source teaching RISC-V in this way and it would be tedious for newbies, in the same way as if they were first taught how to implement a floating-point library on a CPU without floating-point instructions, instead of being allowed to use the floating-point instructions that any CPU has today.
What are you looking for here? Carry and overflow flags were explicitly not included because of the additional cost for OoO processors.
Let's compare overflow detection on RISC-V vs aarch64:
unsigned 64-bit:
add: RV: add+bltu Arm: adds+bcc
sub: RV: sub+bltu Arm: subs+bcs
mul: RV: mulhu+mul+beqz Arm: umulh+mul+cbz
unsigned 32-bit:
add: RV: addw+bgeu Arm: adds+bcc
sub: RV: subw+bgeu Arm: subs+bcs
mul: RV: mul+slli+beqz Arm: umul+cmp lsr 32
signed 64-bit:
add: RV: add+slt+slti+beq Arm: adds+bcc
sub: RV: sub+slt+slti+beq Arm: subs+bcs
mul: RV: mulh+mul+srai+beq Arm: smulh+mul+cmp asr 63
signed 32-bit:
add: RV: addw+add+beq Arm: adds+bvc
sub: RV: subw+sub+beq Arm: subs+bvs
mul: RV: mul+sext.w+bew Arm: smul+asr+cmp asr 31
So it's on par for unsigned, and takes two additional independent instructions for signed 64-bit and one for signed 32-bit.For teaching, using unsigned XLEN-bit values by default is probably a good idea anyway.
> indexed addressing
I'm not sure how much this actually matters in practice. It's nice when you access multiple arrays at the same index, such that you only need to implement one index instead of every pointer. Such loops are often vectorized, and the indexed loads become useless, once you read two values from an array index, e.g. an array of structs.
Edit: removed measurements, because I'm not sure they are correct, might add back later.
Ok, this time I have a proper benchmark.
The XuanTie C910 core supports a custom extension with indexed loads [0] and I got my access to a MILK-V Pioneer server with that CPU working again.
As a quick benchmark I used a self compile of the chibicc C compiler: https://godbolt.org/z/4MMxsEarE
Measuring with the equivalent of rv64gcb and rv64gcb_xtheadmemidx, the xtheadmemidx variant ended up about 0.3% faster on the same core.
[0] https://github.com/XUANTIE-RV/thead-extension-spec/blob/mast...
- learn assembly as subroutines inside your "daily driver" language on your regular PC, which is going to be x64
- microcontroller with in-circuit debugger where you can connect it to flashing lights (obvious candidate is Arduino, which is AVR, or STM32 which is ARM)
Back in the day the first of these was easier in environments like BBC Basic inline assembler or MS-DOS COM files (which are headerless executables that can be extremely small.) You could also learn either of those in emulators.
The modern CPU with orthogonal instruction set is just as easy (possibly easier because you have more and larger registers, making it easier to get ‘real’ results) until you start to look at performance.
Then, you hit the problem of having to understand how your target CPU does out-of-order execution, how large its caches are, how they are organized, etc.
Modern CPUs out there that have very little of that exist, though.