Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

161–170 of 297 posts

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

#161
post #69

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…

I struggled with C until I learned to hex and assembly program on the 68HC11. Maybe I'm just a moron, but things like pointers for a complete beginner seemed so abstract and obtuse until I learned how to do indirect addressing in assembly, then suddenly it was painfully obvious why C had pointers and how they worked. Before that I just mostly used Python where it's far more abstracted away. People forget that many fe…

That's why some people see the C language as "portable assembly". I think C is at its best when you want Assembly-like memory addressing flexibility but don't want to deal with instruction-set specific idiosyncrasies.

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

#162
6502 was my fist assembly language, it’s good from the point of view of learning basics like carry flags and how to do multi byte maths, that’s about all.

If I was to think of the most approachable assembler it would be the ARM assembler for the original ARM2. A real thing of beauty. Which is not what anyone would normally say about any assembly language! I remember going from ARM to MIPS and being utterly horrified by its ugliness compared to ARM!

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

#163

Earlier quoted context omitted.

I believe both are true. Early ARM feels like a refreshed 6502.

Could you say why? It doesn’t feel much like it to me at all!

ARM designers liked and had extensive experience with 6502 - it WAS their bread and butter for a long time - and this might be why the mnemonics are so similar (and carry in subtraction - that might have been for making porting easy, but I won't risk assuming that without a primary source).

They obviously also studied foundational papers on RISC and understood the possibility of having a simple design (such as the 6502, which was very powerful considering its small transistor count) applied to a simple, more regular, instruction set.

Assigning weight to these factors might a futile exercise, as the designers themselves might not agree.

They were not blind to RISC and, therefore, it made sense to put it in the name of the architecture.

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

#164
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 there are other good options.

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

#165
post #146

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…

This is the first time I’ve heard of this, but RISC-V not providing access to carry and overflow status seems insane. E.g. for BigNum implementations and constant-time (branchless) cryptography.

RISC-V does not have carry and overflow flags in the traditional sense. Which is actually great because it needs you don't have to specify the complicated details of how any single instruction might affect the flags. (And yes, it uses compare-and-branch instructions instead.) It does provide suggested insn sequences to check for overflow, which might be executed as a single instruction in a more full-featured implementation.

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

#166

I do not know. I learned it when I was 12, but it was quite challenging for me. Pros: It is very ortagonal, has no memory-to-memory instructions Zero page is like a having 256 generic RISC registers (a bit faster than accessing to other memory areas). Very easy to understand how the assembly is micro-coded Cons: It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code. It i…

> It is impossible to create a "generic" memory pointer with an index >255 without auto-modifying code. Sure it is. Just store your pointer in zero page, set Y to 0 and use the (ZP),Y addressing mode.

Also, compare the "zeropage indirect" address mode of the WDC 65C02, which does exactly this w/o involving any of the index registers.

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

#167

The topic of the 6502 ISA simplicity is a pet peeve of mine, because to me it's clear that anybody thinking that such simplicity is a good thing, never progressed past a hello world. Programming anything of moderate complexity on the 6502 is hard. 8 bits are way too restrictive (e.g. screen addressing on the Commodore 64). Multiplications/divisions need to be hand-rolled. And even 16 bit sums/subtractions are simple…

I probably wrote more 8086 (really 80286 in real mode) assembly than any other assembly. I loved every minute of it, I didn't even mind the segment registers.

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

#168

I cannot agree that the simplicity of the 6502 wins over the 68000. The 68000 has more registers and wider data types: but the registers are all uniformly the same. It's really just two registers A and D, copied a bunch of times in to D0 to D7, and A0 to A7. Whatever you can do with D0 can be done with D3 and so on. Some A's are dedicated, like for a stack pointer. Simplicity of structure has to be balanced with simp…

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…

I think one of the values 6502 provides is that it has so many retro platforms. Apple ][, NES, Atari 2600, BBC, C64, they all use 6502. If you want to do something cool retro stuffs that a lot of people today still enjoy, that's the best bet.

But again Z80 looks like a very good option too because it has GB/GBC plus ZX Spectrum. The same goes to 68K -- Mac 68K, Sega Genesis and Neogeo are popular hits.

When I was writing my reply to another question (https://news.ycombinator.com/item?id=42891200), I was thinking about a new software engineering education system which starts from a retro platform and goes up from there. Maybe all three can fit the bill. I'm very much against the "elegant/pure" way of teaching.

BTW totally agree 6502 essentially has 3 registers. You don't get to touch the others.

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

#169
post #146

Earlier quoted context omitted.

This is the first time I’ve heard of this, but RISC-V not providing access to carry and overflow status seems insane. E.g. for BigNum implementations and constant-time (branchless) cryptography.

RISC-V does not have carry and overflow flags in the traditional sense. Which is actually great because it needs you don't have to specify the complicated details of how any single instruction might affect the flags. (And yes, it uses compare-and-branch instructions instead.) It does provide suggested insn sequences to check for overflow, which might be executed as a single instruction in a more full-featured impleme…

Those sequences of instructions transform the cheapest arithmetic operations into very expensive operations and they make unachievable the concurrent execution of up to 8 arithmetic instructions, which is possible in other modern CPU cores.

Using instruction fusion of a pair of instructions to achieve the effect of indexed addressing, but in a many times more complex and more inefficient way, is believable even if ugly.

Using instruction fusion to fuse the long sequence needed for checking overflow into a single operation is unbelievable.

Even if that were done, the immense discrepancy in complexity between detecting overflow with one extra XOR gate in a 64-bit adder that may have hundreds of gates, depending on its speed, and an instruction decoder capable of fetching ahead and decoding the corresponding long instruction sequence into one micro-operation is ridiculous.

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

#170

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…

I think one of the values 6502 provides is that it has so many retro platforms. Apple ][, NES, Atari 2600, BBC, C64, they all use 6502. If you want to do something cool retro stuffs that a lot of people today still enjoy, that's the best bet. But again Z80 looks like a very good option too because it has GB/GBC plus ZX Spectrum. The same goes to 68K -- Mac 68K, Sega Genesis and Neogeo are popular hits. When I was wri…

If you want to do something cool retro stuffs that a lot of people today still enjoy, that's the best bet.

This shouldn't be discounted, since it has great pedagogical value in itself. On the other hand, personal opinion here, is that not many things are transferable to modern ISAs. Even back in the 90's, we were shown to work on MIPS instead. 68k is very nice to read and write, almost feels like higher language, but overall ROI for newer stuff is maybe just jump into Neon, x86_64, or as someone said RV directly. It's not _THAT_ hard. It gets complex as programs grow though.

Post reply on HN