Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

NOTE: This is not my code and should not be accepted as an answer. I found this while working on a different CG problem to emulate an 8086 CPUto emulate an 8086 CPU. The included text file credits David Stafford, but that's the best I could come up with.

NOTE: This is not my code and should not be accepted as an answer. I found this while working on a different CG problem to emulate an 8086 CPU. The included text file credits David Stafford, but that's the best I could come up with.

NOTE: This is not my code and should not be accepted as an answer. I found this while working on a different CG problem to emulate an 8086 CPU. The included text file credits David Stafford, but that's the best I could come up with.

Source Link
JoeFish
  • 711
  • 6
  • 9

8086 Machine code - 30 bytes.

NOTE: This is not my code and should not be accepted as an answer. I found this while working on a different CG problem to emulate an 8086 CPU. The included text file credits David Stafford, but that's the best I could come up with.

I'm posting this because it's clever, short, and I thought you'd want to see it.

It makes use of overlapping opcodes to pack more instructions in a smaller space. Amazingly clever. Here is the machine code:

B0 13 CD 10 B3 03 BE A0 A0 8E DE B9 8B 0C 32 28 88 AC C2 FE 4E 75 F5 CD 16 87 C3 CD 10 C3 

A straight-up decode looks like this:

0100: B0 13 mov AL, 13h 0102: CD 10 int 10h 0104: B3 03 mov BL, 3h 0106: BE A0 A0 mov SI, A0A0h 0109: 8E DE mov DS, SI 010B: B9 8B 0C mov CX, C8Bh 010E: 32 28 xor CH, [BX+SI] 0110: 88 AC C2 FE mov [SI+FEC2h], CH 0114: 4E dec SI 0115: 75 F5 jne/jnz -11 

When run, when the jump at 0x0115 happens, notice it jumps back to 0x010C, right into the middle of a previous instruction:

0100: B0 13 mov AL, 13h 0102: CD 10 int 10h 0104: B3 03 mov BL, 3h 0106: BE A0 A0 mov SI, A0A0h 0109: 8E DE mov DS, SI 010B: B9 8B 0C mov CX, C8Bh 010E: 32 28 xor CH, [BX+SI] 0110: 88 AC C2 FE mov [SI+FEC2h], CH 0114: 4E dec SI 0115: 75 F5 jne/jnz -11 010C: 8B 0C mov CX, [SI] 010E: 32 28 xor CH, [BX+SI] 0110: 88 AC C2 FE mov [SI+FEC2h], CH 0114: 4E dec SI 0115: 75 F5 jne/jnz -11 010C: 8B 0C mov CX, [SI] 

Brilliant! Hope you guys don't mind me sharing this. I know it's not an answer per se, but it's of interest to the challenge.

Here it is in action:

Running