diff --git a/config.json b/config.json index 0e40e01..432fed7 100644 --- a/config.json +++ b/config.json @@ -809,6 +809,14 @@ "practices": [], "prerequisites": [], "difficulty": 9 + }, + { + "slug": "assemble", + "name": "assemble", + "uuid": "17337704-ef28-490b-bbdd-f8e3f51e326b", + "practices": [], + "prerequisites": [], + "difficulty": 10 } ] }, diff --git a/exercises/practice/assemble/.docs/instructions.md b/exercises/practice/assemble/.docs/instructions.md new file mode 100644 index 0000000..1b7760e --- /dev/null +++ b/exercises/practice/assemble/.docs/instructions.md @@ -0,0 +1,141 @@ +# Instructions + +In this exercise, you will define the syntax and execution model for a small assembly-like language inspired by the `x86-64` assembly language. + +The goal is to formalize how code is written, parsed, and executed within a constrained environment. + +## Execution Model + +Your assembly code will be written inside a special construct: + +```lean +let program := assemble!( + -- assembly code here +) +``` + +This construct must produce a **program**, which simulates a function that executes the assembly code and returns a value. +This program is then invoked using the following syntax, where `a`, `b`, `c`, etc. are arguments: + +```lean +let result := program(a, b, c, ...) +``` + +All arguments and the return value are _64-bit signed integers_. +A maximum of _6 arguments_ is allowed. + +## Registers + +The return value and all arguments are passed in **registers**. +Your language must support the following registers: + +| register | role | +|----------|--------------| +| `rdi` | 1st argument | +| `rsi` | 2nd argument | +| `rdx` | 3rd argument | +| `rcx` | 4th argument | +| `r8` | 5th argument | +| `r9` | 6th argument | +| `rax` | return value | + +Registers start with a default value of `0`, unless they are used to pass arguments to the function. + +For example, in the following program, all registers have a value of `0` with the exception of `rdi`, which is initialized with `10`, and `rsi`. which is initialized with `-20`: + +```lean +program(10, -20) +``` + +The return value of the program is always stored in `rax`. + +Note that register names are _case-insensitive_. +This means that `rax`, `RAX` and `rAx` all refer to the same register. + +## Assembly code + +Each line in the assembly code can be of two forms: + +- **Labels** mark specific places of the program to be used by some instructions. +- **Instructions** represent operations executed by the program. + +Unless modified by some instruction, the execution flow of the program proceeds linearly. +This means that a previous line is fully executed before the line after it is executed. + +### Labels + +Labels have the following syntax: + +```lean +