Live data from Hacker News

I believe 6502 instruction set is a good first assembly language

nemanjatrifunovic.substack.com

71–80 of 297 posts

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

#71
The hairy part the 6502 instruction set is Subtract With Carry, and the confusion about how the carry flag works as a result of subtracting or comparing.

SBC is implemented by adding the ones-complement (XOR FF) of the number or register. And the carry flag is backwards compared to other architectures, such as the Z80. On input, Carry Set means that you don't want an additional one subtracted, and Carry Clear means you do want an additional one subtracted. Then on output, Carry Set means that no borrow took place, and Carry Clear means that borrow took place. When borrow takes place, you get an additional one subtracted, and that lets you chain the low bytes up to the high bytes and subtract bigger numbers.

CMP is like SBC, except it always adds the extra one whether your input carry is set or not, making it act like you'd expect comparison to act.

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

#72
post #5

I’ve only ever learned two assembly languages: 6502 (when I was in elementary school in the early 80s) and 370 (my senior year of high school when I had access to the UIC mainframe thanks to taking night classes there). I can roughly follow the output of godbolt on those rare occasions that I’m curious enough to bother, but the complexity of modern CPUs and computer architectures are such that I don’t know that I rea…

Same, learned as a kid. What was your motivation? Mine was wanting to make games and hitting the performance wall in basic.

That's what did it for me, too. The magazines at the time said that if you wanted to make your game run faster, you had to write parts of it in assembly. I was fortunate that no one told me that was supposed to be harder. I just knew that it was different, and it never occurred to me to be leery of it.

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

#73
I agree with the article. The 6502 was the first CPU I wrote a lot of machine code for both on the Acorn Atom, where the Basic had a buildin assembler, and the Atari XL-800, for which some roommates and I programmed a compiler in Basic and next made it self hosted.

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

#74

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.

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

#75

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…

> Can anyone speak on how it is to move from an older assembly, to a modern CPU?

The modern CPU with orthogonal instruction set is just as easy (possibly easier because you have more and larger registers, making it easier to get ‘real’ results) until you start to look at performance.

Then, you hit the problem of having to understand how your target CPU does out-of-order execution, how large its caches are, how they are organized, etc.

Modern CPUs out there that have very little of that exist, though.

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

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

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

#77

Earlier quoted context omitted.

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.

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.

[deleted]

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

#78

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…

Spending a couple of months tinkering with hardware and programming assembly will make you understand the basics of how a computer works in a totally different way than other high level languages will. I haven't programmed a single line of assembly after high school (back in the 80s...), but the fundamental understanding of how operations are executed, how registries work makes it so much easier to understand the whys, the ifs and buts of programming and optimization. And you'll certainly start to appreciate clean, effective code.

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

#79

I prefer RISCV as an starting assembly language because: it has good design, it's more intuitive, it has modern language and tool support (GCC, LLVM, Rust, etc.), and it runs on QEMU and real available hardware.

> real available hardware Last I checked the 65C02 was still being manufactured and sold. It can also at a blazing 14 MHz.

*run
Post reply on HN