Remix.run Logo
jgrahamc 11 hours ago

In my 6502 hacking days, the presence of an exclusive OR was a sure-fire indicator you’d either found the encryption part of the code, or some kind of sprite routine.

Yeah, sadly the 6502 didn't allow you to do EOR A; while the Z80 did allow XOR A. If I remember correctly XOR A was AF and LD A, 0 was 3E 01[1]. So saved a whole byte! And I think the XOR was 3 clock cycles fast than the LD. So less space taken up by the instruction and faster.

I have a very distinct memory in my first job (writing x86 assembly) of the CEO walking up behind my desk and pointing out that I'd done MOV AX, 0 when I could have done XOR AX, AX.

[1] 3E 00

wavemode 10 hours ago | parent | next [-]

> CEO walking up behind my desk and pointing out that I'd done MOV AX, 0 when I could have done XOR AX, AX

Now that's what I call micromanagement.

(sorry couldn't resist)

xigoi 10 hours ago | parent | next [-]

The real joke is that a CEO had actual technical knowledge instead of just being there for decoration.

jgrahamc 10 hours ago | parent | prev | next [-]

He was right though. We were memory and cycle constrained and I'd wasted both!

mkornaukhov 9 hours ago | parent | prev | next [-]

Similarly, the CEO couldn't resist the outstanding optimization of memory and execution speed!

6510 7 hours ago | parent [-]

No one believes this story.

jgrahamc 6 hours ago | parent [-]

I am sad you don't believe this story. The CEO was very technical and this is exactly the sort of thing he would spot.

bombcar 6 hours ago | parent | next [-]

People don't realize that in the era of dinosaurs where MASM ruled and assembly walked the earth, there basically WEREN'T CEOs who didn't know the details, because all the companies doing this stuff were pretty small at the time (and the CEO may have been writing it himself a few years before).

assimpleaspossi 15 minutes ago | parent | next [-]

In the era of dinosaurs, neither MASM nor Windows existed but we still did assembly or micro-coding (machine coding) or flipped switches.

Analemma_ 5 hours ago | parent | prev [-]

There was a time when Bill Gates wrote code for Microsoft, and he was actually quite good at it.

nomel 3 hours ago | parent [-]

Not sure why this was voted down. He was very technical, especially for the time: https://www.thecrimson.com/article/2025/6/7/bill-gates-reuni...

OrderlyTiamat 5 hours ago | parent | prev | next [-]

My first part time dev job as a student featured me walking in on our CEO who showed me he was recompiling his kernel to enable some features. I'm quite sure he was just doing that to impress the students, but at least he knew how to!

6510 4 hours ago | parent | prev [-]

Similarly, if you told people in the 80's that it would be the opposite in the future no one would believe it either.

Not even the developers are very technical in the future!

Woah, really? And they still manage to write good software?

Of course not, if good software would be standing next to their bed at 4 am they would scream who are you what are you doing here? help! help! Someone, make it go away!

crest 4 hours ago | parent | prev | next [-]

I had to pad the code for alignment reasons. ;-)

ksherlock 3 hours ago | parent | prev [-]

I mean, he IS the Chief EORfficer

stevefan1999 9 hours ago | parent | prev | next [-]

> In my 6502 hacking days, the presence of an exclusive OR was a sure-fire indicator you’d either found the encryption part of the code, or some kind of sprite routine.

Correct. Most ciphers of that era should be Feistel cipher in the likes of DES/3DES, or even RC4 uses XOR too. Later AES/Rijndael, CRC and ECC (Elliptic Curve Cryptography) also make heavy use of XOR but in finite field terms which is based on modular arithmetic over GF(2), that effectively reduces to XOR (while in theory should be mod 2).

OhMeadhbh 8 hours ago | parent | next [-]

I was going to say "but RC4 and AES were published well after the 6502's heyday," but NESes were completely rocking it in '87 (and I'm told 65XX cores were used as the basis for several hard drive controllers of the era.) Alas, the closest I ever came to encryption on a (less than 32-bit system) was lucifer on an IBM channel controller in the forever-ago and debugging RC5 on an 8085.

kjs3 7 hours ago | parent [-]

I'm told 65XX cores were used as the basis for several hard drive controllers of the era

Western Design Center is still (apparently) making a profit at least in part licensing 6502 core IP for embedded stuff. There's probably a 6502 buried and unrecognized in all sorts of low-cost control applications laying around you.

RC5 on an 8085

Oof. Well played.

PaulHoule 6 hours ago | parent [-]

I dunno. The 6502 has been a $2 part for a long time but needs RAM and some glue logic, for a similar price you can get an AVR-8 [1] or ESP-32 [2] and get some RAM and GPIO.

[1] faster, more registers than the IBM 360, << 64k RAM

[2] much faster, 32bit, >> 64k RAM

rzzzt 6 hours ago | parent | next [-]

There are uC versions like the W65C134S: https://www.westerndesigncenter.com/wdc/w65c134s-chip.php

kjs3 5 hours ago | parent | prev [-]

I dunno.

You don't know what, exactly? You can go to the web site and see what they are selling.

The 6502 has been a $2 part for a long time

I doubt that for an IP license at any volume such a thing would make sense.

but needs RAM and some glue logic

Sure? Embedded in whatever you're building.

for a similar price you can get...

Oh, sorry...my bad. You were doing it the HN way: "Don't actually read what was written for comprehension...just take your first knee jerk and tell them how you would obviously do it better.".

ASalazarMX 6 hours ago | parent | prev [-]

Reading cryptography was that advanced at that time, I'm even more surprised that the venerable Norton Utilities for MS-DOS required a password, that was simply XORed with some constant and embedded in the executables. If the reserved space was zeroes, it considered it a fresh install and demanded a new password.

If it had been properly encrypted my young cracker self would have had no opportunity.

vanderZwan 10 hours ago | parent | prev | next [-]

Hah, we commented on the exact same paragraph within a minute of each other! My memory agrees with your memory, although I think that should be 3E 00. Let me look that up:

https://jnz.dk/z80/ld_r_n.html

https://jnz.dk/z80/xor_r.html

Yep, if I'm reading this right that's 3E 00, since the second byte is the immediate value.

One difference between XOR and LD is that LD A, 0 does not affect flags, which sometimes mattered.

sfink 4 hours ago | parent | next [-]

What is this "LD A, 0" syntax? Is it a z80 thing?

One of the random things burned into my memory for 6502 assembly is that LDA is $A9. I never separated the instruction from the register; it's not like they were general purpose. But that might be because I learned programming from the 2 books that came with my C64, a BASIC manual and a machine code reference manual, and that's how they did it.

I learned assembly programming by reading through the list of supported instructions. That, and typing in games from Compute's Gazette and manually disassembling the DATA instructions to understand how they worked. Oh, and the zero-page reference.

Good times.

Narishma 2 hours ago | parent [-]

> One of the random things burned into my memory for 6502 assembly is that LDA is $A9. I never separated the instruction from the register; it's not like they were general purpose.

You had LDA and LDX and LDY as separate instructions while the Z80 assembler had a single LD instruction with different operands. It's the same thing really.

sfink an hour ago | parent [-]

Right, though the LD? and ST? instructions were kind of exceptions. You could only do arithmetic and stack and bitwise ops (and, or, eor, shift, rotate) with A, never X nor Y. Increment and decrement were X/Y only. You couldn't even add two registers together without stashing one in memory.

jgrahamc 10 hours ago | parent | prev [-]

You're right. Of course, it's 3E 00. Not sure how I remembered 3E 01. My only excuse is that it was 40 years ago!

favorited 4 hours ago | parent | prev | next [-]

"Prefer `xor a` instead of `ld a, 0`" is basically the first optimization that you learn when doing SM83 assembly.

https://github.com/pret/pokecrystal/wiki/Optimizing-assembly...

anonzzzies 10 hours ago | parent | prev | next [-]

3E 00 : I was on MSX and never had an assembler when you so I only remember the Hex, never actually knew the instructions; I wrote programs/games by data 3E,00,CD,etc without comments saying LD A as I never knew those at the time.

unnah 8 hours ago | parent [-]

Umm... how did you manage to learn those hex codes? You just read a lot of machine code and it started to make sense?

jgrahamc 8 hours ago | parent | next [-]

I started out writing machine code without an assembler and so had to hand assemble a lot of stuff. After a while you end up just knowing the common codes and can write your program directly. This was also useful because it was possible to write or modify programs directly through an interface sometimes called a "front panel" where you could change individual bytes in memory.

Back in 1985 I did some hand-coding like this because I didn't have access to an assembler: https://blog.jgc.org/2013/04/how-i-coded-in-1985.html and I typed the whole program in through the keypad.

stevekemp 8 hours ago | parent [-]

Same here. On/For the ZX Spectrum, looking up the hex-codes in the back of the orange book. At least it was spiral-bound to make it easier.

Later still I'd be patching binaries to ensure their serial-checks passed, on Intel.

af78 7 hours ago | parent | prev | next [-]

I had a similar experience of writing machine code for Z80-based computers (Amstrad CPC) in the 90's, as a teenager. I didn't have an assembler so I manually converted mnemonics to hex. I still remember a few opcodes: CD for CALL, C9 for RET, 01 for LD BC, 21 for LD HL... Needless to say, the process was tedious and error-prone. Calculating relative jumps was a pain. So was keeping track of offsets and addresses of variables and jump targets. I tended to insert nops to avoid having to recalculate everything in case I needed to modify some code... I can't say I miss these times.

I'm quite sure none of my friends knew any CPU opcode; however, people usually remembered a few phone numbers.

senderista 6 hours ago | parent | prev | next [-]

It wasn't unusual in the 80s to type in machine code listings to a PC; I remember doing this as an 8-year-old from magazines, but I didn't understand any of the stuff I was typing in.

anonzzzies 4 hours ago | parent | prev | next [-]

Typing from mags, getting interested in how the magic works by learning to use a hex monitor and trying out things. I was a kid so time enough.

I didn't know you could do it differently for years after I started.

kragen 8 hours ago | parent | prev | next [-]

The instruction sets were a lot simpler at the time. The 8080 instruction set listing is only a few pages, and some of that is instructions you rarely use like RRC and DAA. The operand fields are always in the same place. My own summary of the instruction set is at https://dercuano.github.io/notes/8080-opcode-map.html#addtoc....

amirhirsch 8 hours ago | parent | prev [-]

I implemented a PDP-11 in 2007-10 and I can still read PDP-11 Octal

mmphosis 5 hours ago | parent | prev [-]

Try to keep the value 0 in the Y register.

  echo tya|asm|mondump -r|6502
                                A=AA X=00 Y=00 S=00 P=22 PC=0300  0
  0300- 98        TYA           A=00 X=00 Y=00 S=00 P=22 PC=0301  2