Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

131–140 of 297 posts

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

#131

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 a lot with it in the mid 2000s. The Thumb mode is probably slightly easier to learn than the original Arm mode, but neither is as satisfactory as RISC-V.

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

#132
post #121

Earlier quoted context omitted.

One of the downsides having learned to code close to the metal on old CPUs is that you understood how that system worked and it‘s easy to assume assembler and the resulting machine code are the truth, but on modern CPUs that‘s a lie. A modern beefy out of order CPU will do insane optimization dynamically at runtime and the instructions you carefully scheduled to avoid register spills are nothing but a suggestion to t…

That was never about the instruction set, it was more about the operating system -- or lack of one. As for modern CPUs and OoO etc, that's only about performance. The CPU, no matter sophisticated, must produce exactly the same results as the simplest in-order CPU. Hardware is never going to spill a register to RAM when you didn't write that. The maximum that is going to happen -- and this is pretty recent -- is that…

The performance is the point. 8-bit CPUs are so slow assembler could be - often had to be - hand-optimised for speed.

You can't do that on modern CPUs, because the nominal ISA has a very distant relationship to what happens inside the hardware.

The code you write gets optimised for you dynamically, and the machine is better at it than you are.

You may as well write in a high-level language, because the combination of optimising compilers with optimising hardware is probably going to be faster than any hand-written assembler. It's certainly going to be quicker to write.

The 68000 is a very nice, clean machine to code for, but the main point of doing it today is historical curiosity. It's quite distant from modern computing.

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

#133

Can anyone speak on how it is to move from an older assembly, to a modern CPU? I asked to take an assembly class in local/public college, and was told they wouldn't hold the class because not enough students were interested. This was in 1998, and I truly couldn't believe my ears. 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 w…

Modern CPUs are more difficult to program in assembly. 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 th…

> Because it lacks many features of normal ISAs

Do you have some examples of this?

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

#134
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/

I wish there were books like this today, that could lead a kid from knowing virtually nothing to a graduate level understanding of computer architecture, digital storage, logic and set theory, graphics, mathematical modelling, networking, numerical methods, signal processing, electrical engineering, software design, ...

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

#135
I learned 6502 as a teenager in the 70s (after learning 6800 first). When 68k came along, I immediately recognized it was a superior architecture.

Nevertheless, when I went to teach a short intro to CPU class to high school students recently, I chose the venerable 6502 for programming. Why? Because performing the 8-bit arithmetic and performing hand assembly are all very manageable on the 6502. Any 8-bit CPU would do, frankly, but the connection between 6502 and early microcomputer history is intriguing (and I was familiar with it).

Everyone here is talking about how there are better assembly languages to learn first, but I wonder how many of them are practical for hand assembly. I still maintain that learning (and debugging software for) any CPU architecture beyond the 6502 was easy because of the skills I learned as a teenager, hand assembling 6502 code. That experience put me miles ahead of my colleagues who didn't have that experience when it came to working with low-level coding in the decades to follow.

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

#137

Strong disagree. The RV32E subset of the RISC-V spec is even simpler than 6502 and has good modern support in cheap microcontrollers (CH32V003 etcetera) and widely available simulators.

RISC-V has a simple instruction encoding, but the 6502 has 151 instructions total.

Counting instructions is problematic.

6502 has 56 mnemonics, RV32I/RV32E has 37.

But mnemonics are arbitrary. Are BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS really different instructions, or just one instruction with a field specifying the condition.

If you look at 8080 and Z80 assembly languages you see the same binary instructions represented with different mnemonics and some things that have different mnemonics in one are the same mnemonic with different arguments in the other.

6502, original, has 151 of the 256 eight bit opcodes used, but when you add in the immediate data or address it has millions of possible instructions:

with ABS ABS,X ABS,Y modes: ADC, AND, CMP, EOR, LDA, ORA, SBC, STA

with ABS ABS,X modes: ASL, DEC, INC, LDX (act ABS,Y), LDY, LSR, ROL, ROR

with ABS mode: BIT, CPX, CPY, JMP, JSR, STX, STY

So that's (38 + 28 + 7) * 65536 = 3,080,192 instructions right there.

Immediate and the various Zero Page instructions add another few thousand.

Similarly with RISC-V RV32I when you fill in the Rd, Rs1, Rs2 fields and immediates/offsets there are again many millions of possible instructions.

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

#138

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…

> Even getting an OS, compiler etc is not that easy.

There's a GCC fork [0], macro11 [1] (GCC and clang also both have macro11 backends), ack [2] and more.

Getting hold of a modern compiler is trivial.

> It's kind of hard to get hold of a PDP-11 these days.

The PiDP-11 [3] emulator that runs on a Pi, is fairly popular among the retro crowd. So sourcing something hardware wise that behaves that way is easily possible.

The Computer History Simulation Project [4] will give you easy access to simulating a PDP-11 on just about anything that you own.

But if you want the original hardware, then they're in the $400-500 range, in my area. Easy to source.

[0] https://github.com/JamesHagerman/gcc-pdp11-aout

[1] https://gitlab.com/Rhialto/macro11

[2] https://github.com/davidgiven/ack

[3] https://obsolescence.wixsite.com/obsolescence/pidp-11

[4] https://github.com/simh/simh

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

#139

Earlier quoted context omitted.

That was never about the instruction set, it was more about the operating system -- or lack of one. As for modern CPUs and OoO etc, that's only about performance. The CPU, no matter sophisticated, must produce exactly the same results as the simplest in-order CPU. Hardware is never going to spill a register to RAM when you didn't write that. The maximum that is going to happen -- and this is pretty recent -- is that…

The performance is the point. 8-bit CPUs are so slow assembler could be - often had to be - hand-optimised for speed. You can't do that on modern CPUs, because the nominal ISA has a very distant relationship to what happens inside the hardware. The code you write gets optimised for you dynamically, and the machine is better at it than you are. You may as well write in a high-level language, because the combination of…

You can do that on modern CPUs, and I do. If you can't do it, it's simply because you haven't studied the CPUs closely enough.

I write compilers, and I write critical routines by hand when compilers don't do a good job.

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

#140

Earlier quoted context omitted.

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…

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 all its peculiarities, but a too simple ISA is even worse, because every simple operation must be implemented by a complex sequence of instructions that is easy to forget and to get wrong.

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.

The didactic examples of using RISC-V usually do not check for any errors, which is not acceptable in any critical application. I find funny that sometimes the same people who claim that the unsafe RISC-V ISA is good also claim that C and C++ are bad, because with default compilation options they are unsafe in comparison with e.g. Rust.

Post reply on HN