modus
Menu
On this page

The module assemble

The assembler as a module: the first program of modus that writes a program. It reads a text of x86-64 assembly in the syntax of AT&T and writes a module file into memory that the caller lends .

What it is for. A machine with no host makes a module. The console calls it in a call host, then isolates the module that it wrote:

> isolate("assemble")
> f = buffer(4)
> n = assemble("export add(a: Integer, b: Integer) -> Integer; add: mov %rdi, %rax; add %rsi, %rax; ret", f)
> isolate_memory("adder", f, n)
> add(2, 3)
5

It has no entry: it runs in the call host of its caller, with no grant. Its memory is an arena of the budget of the call host, made at each call and ended at its return: the copy of the text and the workspace of the assembler. So an idle module holds no page of a workspace.

See: Module contract: The assembler

assemble module with no entry

Hash
a6d4759a52188bf1e1921115d3bcdc82715f06ad16b5814c24d0c4cdfc4e1dfa
Size
176128 bytes
Exports
2
Imports
0
Imported by
0
License
MIT

The assembler as a module: the first program of modus that writes a program

FactValue
KindModules with no entry
Sourcesrc/modules/system/assemble
Boot imageyes: in the boot image, 176128 bytes in this build
Build settingsnone: the defaults of the source
Importsnone
Imported bynone

Neighbours

It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.

Exports

ExportWhat it does
assemble(source: Bytes(Read), file: Handle(Read, Write)) -> Integerwrites the module file of an assembly text into a memory object, and gives the bytes of the file
assemble_program(source: Bytes(Read), file: Handle(Read, Write), hash: Bytes(Append)) -> Integerwrites the module file of an assembly text into a memory object, appends its BLAKE3 hash, and gives the bytes of the file

assemble

assemble(source: (Read), file: (Read, Write)) -> 

assemble writes the module file of an assembly text into a memory object, and gives the bytes of the file.

source is the text, 1 byte to 4 MiB: statements separated by a new line or by ;, in the syntax of AT&T, with the directives section code, section data, export name(a: Integer, b: Text) -> Integer, byte, quad, zero, align, unit and global; a quad of a label is its address, which the module rebases at its load, and unit starts the next unit of a program, whose labels other units reach only through global. file is a memory object that the caller lends to write; the file starts at its first byte. The copy of the text and the tables of the assembler are memory of the budget of the call host, for the time of the call: a text past the bounds of one source (128 KiB of code, 2048 labels) takes the tables of a program (512 KiB of code, 128 KiB of data, 16384 labels, 16384 operands that name a label, 2048 rebases), and a budget that cannot pay them fails with its error record. A text that the assembler does not take whole fails with -1 and the error record Bad_Byte: the value is the offset of the first byte of the statement or the operand that it refuses, and found is that byte; the log has the line, the column and the reason. A memory object smaller than the file fails with Too_Small, and the limit is the bytes of the file.

Parameters
  • source: (Read)
  • file: (Read, Write)
Result
When it fails
a negative result, and the error record
Source
src/modules/system/assemble/assemble.odin:220

assemble_program

assemble_program(source: (Read), file: (Read, Write), hash: (Append)) -> 

assemble_program writes the module file of an assembly text into a memory object, appends its BLAKE3 hash, and gives the bytes of the file.

source and file are those of assemble, and the refusals are its refusals. hash takes the 32 bytes of the BLAKE3 hash of the file after its count: a stage of a bootstrap compares the hash of two builds with no second read of the files. A hash with less than 32 bytes of room fails with Too_Small before the text is read, and the limit is 32.

Parameters
  • source: (Read)
  • file: (Read, Write)
  • hash: (Append)
Result
When it fails
a negative result, and the error record
Source
src/modules/system/assemble/assemble.odin:231

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

Bytes wire form

A wire form of the module contract: one word of a call. Bytes with no description.

Handle wire form

A wire form of the module contract: one word of a call. A handle that the caller lends for the time of the call, in a register.

Integer wire form

A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.

Error_Record record of a module

A record of the module assemble: 56 bytes, aligned on 8 bytes, 0 bytes of padding.

  • kindi6408 bytes
  • uniti6488 bytes
  • operationi64168 bytes
  • argumenti64248 bytes
  • valuei64328 bytes
  • limiti64408 bytes
  • foundi64488 bytes