0

I'm attempting to write an assembler for Notch's DCPU-16 spec. The original spec for this CPU can be found here.

The relevant lines:

SET A, 0x30 ;7c01 0030

...

IFN A, 0x10 ;c00d

I understand the instructions up to this point, but this one to me should be at least 2 words long rather than just 0xc00d

SET A, 0x10 

would be 7c01 0010. so

IFN A, 0x10 

should be 7c0d 0010 shouldn't it?

Why does the b argument in IFN, not cause the instruction to need a [PC++] or nextword component?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Matt Fellows
  • 6,512
  • 4
  • 35
  • 57
  • That is the old spec. The new spec is [here](http://dcpu.com/highnerd/dcpu16.txt) – BlueRaja - Danny Pflughoeft Apr 30 '12 at 17:23
  • Thanks - I was aware of the new spec - but I started implementing it starting with the old one, in order to learn incrementally. – Matt Fellows May 01 '12 at 12:36
  • Link archived at http://web.archive.org/web/20120629091438/http://dcpu.com/doc/dcpu-16.txt – ecm Dec 03 '19 at 19:03
  • First link (from question and in my prior comment) is headed by ["DCPU-16 Specification \ Copyright 2012 Mojang \ Version 1.1 (Check 0x10c.com for updated versions)" (archived here)](http://web.archive.org/web/20120629091438/http://dcpu.com/doc/dcpu-16.txt), second link (from the comment by BlueRaja - Danny Pflughoeft) confusingly enough is headed by ["DCPU-16 Specification \ Copyright 1985 Mojang \ Version 1.1" (archived here)](http://web.archive.org/web/20120629091443/http://dcpu.com/highnerd/dcpu16.txt). – ecm Dec 03 '19 at 21:19
  • In [another question](https://stackoverflow.com/questions/17187712/reducing-size-of-switch-statement-in-emulator) I found a later revision of the specification, headed by ["DCPU-16 Specification \ Copyright 1985 Mojang \ Version 1.7"](http://pastebin.com/raw/Q4JvQvnM). – ecm Dec 04 '19 at 09:04

1 Answers1

3
     0x1f: next word (literal)
0x20-0x3f: literal value 0x00-0x1f (literal)

This is the core part of the spec you are asking about. A literal value between 0 and 31 (0x1f) can be encoded in the opcode. If the value is too large then the literal value needs an extra word, indicated with 0x1f.

So IFN A, 0x10 needs only one word since the 0x10 literal is small enough to fit inside the opcode. The 16-bit opcode breaks down in 6 bits for the b operand, 6 bits for the a operand and 4 bits for the instruction. So b = 0x30 (0x20+literal), a = 0x00 (register A), instr = 0xd (IFN). Put them together with opcode = (b << 10) | (a << 4) | instr; and you get 0xc00d.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536