Skip to main content

Module decode

Module decode 

Source
Expand description

Sixteen bytes back to Inst.

ADR 0041 makes the encoding 1:1, so this is a genuine inverse and not a best effort: decode(encode(i, pc), pc) == i for every instruction, and encode(decode(b, pc), pc) == b for every byte pattern this accepts.

§It is strict, and that is what makes the encoding canonical

A field an opcode does not use must be zero, flags must be zero, and a const.bool payload must be 0 or 1. Bytes that say the same thing in two ways are refused rather than normalised, which is what gives the second half of the round trip: a program has exactly one encoding, so two encodings of it are byte-identical and a diff over encoded code means something.

§What it is for

Tests, the debugger, and disasm — never the dispatch loop. A verified program is executed from its bytes; this is how a human reads them back.

Enums§

Malformed
Why sixteen bytes are not an instruction.

Functions§

decode
Reads one encoded instruction back.