Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

121–130 of 297 posts

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

#121

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…

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 the actual hardware. sigh<

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

#122

Earlier quoted context omitted.

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

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

#123
post #11

Earlier quoted context omitted.

In many decades past, there were no high level languages, and assembly was the only language. It was a very different time. Those people would be equally astonished at our casual computing devices and ignorance at how they work. Oddly enough, my current karma score is 6502. Synchronicity indeed.

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.

> The era in which there was nothing but assembly language was very short-lived.

Hell, I'm not even sure the era existed.

Grace Hopper was creating the first few high level languages for UNIVAC I. A-0 was complete in May 1952. A-2 (the first which saw extensive use) was created in August 1953.

As far as I can tell, UNIVAC I never had an assembler. If you weren't using A-0, programmers were expected to just type in raw machine code. Here is a UNIVAC programming manual from 1953 [1], and there is no mention of an assembler. Oh, and if you think you see instruction mnemonics... no, those are just letters which the CPU instruction maps onto.

Over in the IBM world, at least the 701 launched with a proper symbolic assembler in April 1953. But it also launched with Speedcoding [2], a somewhat higher level language halfway between non-symbolic assembler (it decodes mnemonics, but the programmer has to specify all addresses as absolute numbers) and an interpreter.

None of the other early computers seem to have had assemblers (though some, like the Manchester Mark 1, had high level languages).

There might have been some programmers at IBM who might have had access to a the prototype 701, and the symbolic assembler before Speedcoding existed [3]. But for everyone else, they seem to have gotten access to high-level languages at the same time, or before they got access to assemblers.

[1] http://www.bitsavers.org/pdf/univac/univac1/UNIVAC_Programmi...

[2] https://en.wikipedia.org/wiki/Speedcoding

[3] It's also possible that Speedcoding development was largely finished before the first 701 was operational. I'm finding it hard to find exact dates for that.

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

#124

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

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

#125
post #121

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…

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 memory at small offsets from the SP might be treated as if it was extra registers, and this renaming can be tracked over smallish adjustments to the SP.

"You can't understand what modern CPUs do" is much overblown. Just write good clean code and it will work well on everything.

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

#126

Earlier quoted context omitted.

I guess, it's a matter of perspective. The Z80 is derived from the 8008 (actually the 8080), which was an on-a-chip implementation of the processor of the Datapoint 2200. Notably, the DP2200 was designed around an early Intel shift-register for memory (meaning, sequential memory), hence the multitude of internal registers in order to minimize memory access. (It's probably only for the 8080, which provided better supp…

Zilog Z80 had very significant improvements over Intel 8080. From many points of view it can be considered midway between Intel 8080/8085 and Intel 8086/8088. Besides increasing the number of registers, Z80 has added many features that were standard in any general-purpose computer (e.g. signed integer support and indexed addressing), but which were missing in Datapoint 2200/Intel 8008/Intel 8080, simply because Datap…

I think, this is much about another major difference in the history of both designs: while originally for a different architecture, the DP2200 processor / Intel 8008 was meant to be a CPU for a small computer system from the beginning. The 6800 and in consequence even more so the 6502 was more about a microcontroller for implementing in software what wasn't economically viable to be put in silicon. Notably, it was not meant to be a computer CPU. Thus, the 6502 falls short on many things like support for large stacks, as required for higher languages, or efficient 16-bit operations. (Its philosophy may be better described as, "if it runs, it's good enough, even better so, if it runs cost effectively.")

PS: regarding the DP2200 not being meant as a small system, I'm not so sure about this based on my own reading. But, certainly, it wasn't marketed as such.

And, regarding the educational merits of the 6502, it may be a good second language, as it requires you to think about your implementation. (Personally, I'm more for the PDP-1, which Ed Fredkin – "world's best programmer", no less – once claimed to have inspired IBM's RISC architecture. ;-) )

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

#127

Earlier quoted context omitted.

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 wr…

Lol. I've been programming assembly language since 1980, on at least (that I can remember) 6502, 6800, 6809, 680x0, z80, 8086, PDP-11, VAX, Z8000, MIPS, SPARC, PA-RISC, PowerPC, Arm32, Arm64, AVR, PIC, MSP430, SuperH, and some proprietary ISAs on custom chips.

RISC-V is simply the best ISA I've ever used. It's got everything you need, without unnecessary complexity.

> RISC ISAs were intended to be programmed exclusively in high-level languages and never in assembly language.

That's a misunderstanding. RISC was designed to include only the instructions that high level language compilers found useful. There was never any intention to make assembly language programming difficult.

Some early RISC ISAs did make some of the housekeeping difficult for assembly language programmers by for example having branch delay slots, or no hardware interlocks between things such as loads or long-running instructions such as multiple or divide and the instructions that used their result. So if you counted wrong and tried to access the result register too soon you probably silently got the previous value.

That all went completely out the window as soon as there was a second implementation of the same ISA with a different number of pipeline stages, or more of less latency to cache, or a faster or slower divide instruction. And it was just completely untenable as soon as you got CPUs executing 2 or 3 instructions in each clock cycle instead of 1. The compiler could not calculate when it was safe to use a result because it didn't know what CPU version the code would be running on.

Modern RISC -- anything deigned since 1990 -- is completely fine to program in assembly language.

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

#128
Having programmed the 6502 and struggled with 8-bit arithmetic, I can only say that I don't believe it is a good first language at all. 32-bit ARM2 was so much more intuitive, where each and every instruction could be conditionally executed and there were 12? general purpose 32 bit registers in user mode.

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

#129

Earlier quoted context omitted.

Zilog Z80 had very significant improvements over Intel 8080. From many points of view it can be considered midway between Intel 8080/8085 and Intel 8086/8088. Besides increasing the number of registers, Z80 has added many features that were standard in any general-purpose computer (e.g. signed integer support and indexed addressing), but which were missing in Datapoint 2200/Intel 8008/Intel 8080, simply because Datap…

I think, this is much about another major difference in the history of both designs: while originally for a different architecture, the DP2200 processor / Intel 8008 was meant to be a CPU for a small computer system from the beginning. The 6800 and in consequence even more so the 6502 was more about a microcontroller for implementing in software what wasn't economically viable to be put in silicon. Notably, it was no…

It wasn't marketed as one in the same way the DEC PDP's (Programmed Data Processors) weren't, i.e. "it's not a computer, we swear!"

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

#130

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…

While I learned programming with 6510, I agree that 68000 instruction set was much nicer and easier to read and learn. I would also chose 68000.

This said, 65XX on an early Commodore computers was extremely rewarding to use because there was no memory protection and you could write code altering video memory, mess with sprites, fonts, borders, interrupts, write self modifying code etc etc. 68000 assembly on Amiga was more safe and controlled.

Post reply on HN