Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

171–180 of 297 posts

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

#171

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…

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 would be those few mentioned of which you'd only ever really touch A, X, and Y.

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

#172
I'm curious what people's thoughts are on the 65816 (used by the SNES) instead of the 6502 (the NES instruction set).

Is this author arguing the 6502 is preferable because it's simpler? Or because there are more/better resources for learning?

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

#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.

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

#174
Why not learn a language intended for didactic use?

https://en.wikipedia.org/wiki/MMIX

has a quite deep corpus and what looks to be a good introduction:

https://www.mmix.cs.hm.edu/getstarted.html

(and I say that as a person who owns a much battered copy of Inman & Inman's _Apple Machine Language_)

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

#175

In university we we're taught a version of MIPS that was implemented into a decent simulator with an IDE showing the state of memory and registers with fine grained debug stepping. Some quirks of processor pipelines (i.e. nops after branch) could be enabled for realism or turned off to make things easier for new students. That was pretty great for learning assembly, I can't comment on any other approach - no doubt th…

Sounds like CTU FEE in Prague. I learned a bunch about registers, branch prediction and cache, but most of the assembly went out of my head once the class was over.

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

#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.

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

#178
post #85

Earlier quoted context omitted.

My C64 didn't come with a monitor. I typed one in from a magazine, then learned assembly by entering instructions directly into it. I was so thrilled to discover assemblers later.

I thought I was in heaven when I got the Action Replay cartridge (not the genuine, but a clone with the same software) that came with a monitor, a "freezer", fastloader, and various disk utilities.

Young me envies you so much.

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

#179

Earlier quoted context omitted.

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?

The most important are the lack of integer overflow detection and indexed addressing. Integer overflow detection is required for any arithmetic operation unless it is possible to prove at compile time that overflow is impossible (which is possible mostly for operations with some counters or indices, whose values are confined inside known ranges), while indexed addressing is needed in all loops that access arrays, i.e. extremely frequently from the point of view of the number of actually executed instructions.

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.

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

#180

6502 was my first assembly, though we didn't have an assembler - we entered raw opcodes into the Epyx FastLoad monitor on the C64. You kids with your symbol tables and your fancy mnemonics. a9 01 8d 20 d0 a9 93 20 d2 ff ... When we got a KIM-1, we were able to write meaningful programs on it in a weekend, since we already had memorized all the hex.

I've forgotten so much of that, but I'll go to my grave remembering that LDA #97 JSR $FFD2 writes "A" to the screen.

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.

Post reply on HN