Skip to content

History

Showing with 10 additions and 2 deletions.
  1. +10 −2 Structure-and-concepts.md
12 changes: 10 additions & 2 deletions Structure-and-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ The `instructions` section contains an arbitrary number of *instruction definiti
```
Instruction ::= ID Attribute* '{'
'encoding' ':' EncodingSpec ';'
('assembly' ':' STRING ';')?
('assembly' ':' AssemblySpec ';')?
'behavior' ':' Statement
'}'
```
Expand Down Expand Up @@ -203,8 +203,16 @@ SW { encoding: offset[11:5] :: src[4:0] :: base[4:0] :: 3'b010 :: offset[4:0] ::
We recommend to use [Verilog-style](https://github.com/Minres/CoreDSL/wiki/Literals#verilog-style-literals) integer literals in the encoding, as a C-style bit-literals will not capture leading zeros (e.g., `0b010` == `2'b10`, not `3'b010` as one might expect).

### Assembly format
The `assembly` directive defines the *textual* format of the instruction for use in assembler and disassembler tools.
```
AssemblySpec ::= '{' STRING, STRING '}' | STRING
```
The two strings in the curly-braces-enclosed form are interpreted as the mnemonic and a format string for the argument list.
If only one string is given, it specifies the argument list format, and the instruction's name is used as the mnemonic.

NB: The longer form is useful when the desired mnemonic is not a valid identifier, e.g. because it contains a dot.

The purpose if this statement is to define the *textual* format of the instruction's argument list, for use in assembler and disassembler tools. It follows the format string syntax of the [fmt library](https://fmt.dev/latest/syntax.html#syntax) with some minor extensions. A similar format specification is used by the Python string format() function. The [arg_id identifiers](https://fmt.dev/latest/syntax.html#grammar-token-arg_id) are automatically derived from the named encoding fields (see above), e.g. in
The argument list format follows the format string syntax of the [fmt library](https://fmt.dev/latest/syntax.html#syntax) with some minor extensions. A similar format specification is used by the Python string format() function. The [arg_id identifiers](https://fmt.dev/latest/syntax.html#grammar-token-arg_id) are automatically derived from the named encoding fields (see above), e.g. in
```
encoding: b0010100 :: rs2[4:0] :: rs1[4:0] :: b001 :: rd[4:0] :: b1010011;
assembly: "f{rd}, f{rs1}, f{rs2}";
Expand Down