Skip to main content

Module exec

Module exec 

Source
Expand description

The executable format (D-20).

A header of five stored words, then the code.

§Why an instruction is six bytes

The byte boundary (D-04) maps a byte to a tryte and does not run backwards: a tryte holds 19,683 values and a byte holds 256. An instruction is three trytes, so storing one means splitting each tryte across more than one byte.

Each tryte is biased by 9,841 to make it non-negative, then split into two digits in base 243. Base 243 because it is 3^5, so a digit is a trit shift rather than a multiply, and because it is under 256, so a digit is still a byte. Two digits reach 59,049, past the 19,683 a tryte needs.

Modules§

hdr
Word offsets within the header.

Structs§

Header
A parsed executable header.

Enums§

ExecError
Something wrong with a program or its source.

Constants§

BIAS
Added to a tryte to make it non-negative before splitting.
BYTES_PER_INSTRUCTION
Bytes per instruction.
BYTES_PER_TRYTE
Bytes per tryte in the encoded form.
HEADER_BYTES
Bytes in the header. Header fields are small, so they are stored the way filesystem fields are: three trytes in base 243, one byte each.
HEADER_WORDS
Words in the header.
MAGIC
Identifies an executable. 3^9 + 3^5 + 3 and chosen only to be recognisable.
RADIX
Digits are base 243, as in the filesystem.
RADIX_TRITS
Trits per digit: RADIX is 3 to this power.

Functions§

build
Assembles source for link and returns an executable image.
header
Reads the header, checking the magic and the length.
prelude
Assembler .equ lines naming the format’s constants.
words
Decodes the code as words, for a host checking what a program contains.