Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

101–110 of 297 posts

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

#101

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…

6502 is a better "toy" asm than the Z80, but that's not saying much. It's not even obviously better than the AVR 8-bit insn set. As far as more modern platforms, I think there is a strong case for teaching RISC-V over something like MC68k. RISC-V can be very simple and elegant (in the base integer insn set) while still being very similar to other modern architectures like ARM, Aarch-64 and MIPS. It's also available i…

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 written in high-level programming languages is fine. It should be noted that in the research papers that have coined the name RISC, where there was a list of properties defining what RISC means, one of them was that RISC ISAs were intended to be programmed exclusively in high-level languages and never in assembly language. From this point of view, RISC-V has certainly followed the original definition of the term RISC, by making the programming in assembly language difficult and error prone.

On the other hand, learning assembly programming with RISC-V is a great handicap because it does not expose the programmer to some of the most fundamental features of programming in an assembly language, because RISC-V does not have even many features that existed in Zilog Z80 or in vacuum-tube computers from 70 years ago, like integer overflow detection and indexed addressing.

Someone who has learned only RISC-V has an extremely incomplete image about how a normal instruction set architecture looks like. When faced with almost anyone of the several thousands of different ISAs that have been used during the last three quarters of a century a RISC-V assembly programmer will be puzzled.

6502 is also too quirky and unusual. I agree that among the old ISAs DEC PDP-11 or Motorola MC68000 are better ISAs for someone learning to program in an assembly language from scratch. Writing assembly programs for any of these 2 is much simpler than writing good assembly programs for RISC-V, where things as simple as doing a correct addition are quite difficult (by correct operation I mean an operation where any errors are handled appropriately).

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

#102

Earlier quoted context omitted.

The era in which there was nothing but assembly language was very short-lived. By the time the 1950s were over, we had higher level languages. Like before The Beatles recorded their first album.

6502-based microcomputers like the Apple II shipped with BASIC and a 6502 monitor. The reason is that BASIC and low-level monitors can fit into tiny amounts of memory.

The Apple ][ (not plus) Integer Basic ROMs included an interactive 6502 "Mini Assembler"! That and the Applesoft ROMs also included a disassembler.

https://downloads.reactivemicro.com/Users/Grant_Stockley/App...

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

#104
6502 was my first assembly language (back in the 80s). It was fine. However, when I later had to do some Z80 assembly programming I considered that instruction set a lot nicer. It had more registers. It had a swappable register set. It even had a few 16 bit instructions. Really nice.

I guess most people just give up once they see the ugliness of what they got from Intel.

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

#105
post #8

In addition to be a good starting point for programming, the 8-bit micros are also a good way to begin learning about the hardware side of microprocessor systems, since the external stuff (memory chips, etc.) was correspondingly simpler as well. And without pipelining, you can form a more straightforward mental model of what the system is actually doing. For me, it was Z80, just because Radio Shack had a book on it.…

I think the Z-80 is sadly out of production at this point, but the eZ80 SoC is still available, so hopefully you can still build a hardware CP/M system! Of course there are also synthesizable FPGA implementations, cycle-accurate software implementations, etc.

You can run CP/M on the Agon Light computer, which is indeed based on the eZ80:

https://github.com/TheByteAttic/AgonORIGINS

https://github.com/nihirash/Agon-CPM2.2

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

#106
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…

This is my experience as well, for a lot of features that seem like magic in high level languages. I could somewhat accept pointers even without understanding them, but object-oriented programming with its classes and all was such a mystery to me that I was scared to even try using it.

It's not until I learned assembly language that I understood pointers, and from there, I could implement a basic OOP system in C and finally understand what objects are all about. It only clicked when I learned how to do it from scratch.

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

#108
post #70

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…

The 68K is still a tiny bit awkward, with its 24-bit bus and alignment restrictions and middling support for indexing into arrays (no scale factor). The 68020 is about as close to C as an ISA can get - it’s extraordinarily pleasant.

While I agree that 68020 felt like a great improvement over 68000 and 68010, scaled indexed addressing is an unnecessary feature in any ISA that has good support for post-incremented and pre-decremented addressing.

Scaled indexed addressing is useful in 80386 and successors only because they lack general support for addressing modes with register update, and also because they have INC/DEC instructions that are one-byte shorter than ADD/SUB, so it is preferable to add/subtract 1 to an index register, instead of adding/subtracting the operand size.

Scaled indexed addressing allows the writing with a minimum number of instructions of some loops where multiple arrays are accessed, even when those arrays have elements with different sizes. When all array elements have the same size, non-scaled indexed addressing is sufficient (because you increment the index register with the common operand size, not with 1).

However there are many loops where scaled index addressing is not enough for executing them with a minimum number of instructions, while using post-incremented/pre-decremented addressing still allows the minimum number of instructions (e.g. for arrays of structures or for multi-dimensional arrays).

Unfortunately not even MC68020 has complete support for auto-incremented addressing modes, because besides auto-incrementing with the operand size there are cases when one needs auto-incrementing with the increment in a register, like provided by CDC 6600, IBM 801, ARM, HP PA-RISC, IBM POWER and their successors (i.e. when the increment is an array stride that is unknown at compile-time).

On x86-64, using scaled indexed addressing is a necessity for efficient programs. On the other hand on ISAs like ARM, which have both scaled indexed addressing and auto-indexed addressing, it is possible to never use scaled indexed addressing without losing anything, so in such ISAs scaled indexed addressing is superfluous.

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

#109
post #76

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…

ARM borrowed most of its design from 6502. So if you learn 6502, you've learned many of the tricky parts of ARM (such as how the carry flag works with subtraction). 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.

> ARM borrowed most of its design from 6502

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

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

#110

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…

6502 and 68000 are both perfectly good assembly languages, but I think the best remains PDP-11 assembly. It scans so nicely in octal. :)
Post reply on HN