Skip to content

Commit b8cc733

Browse files
folkertdevehuss
authored andcommittedAug 14, 2024·
add the const operand to docs for inline assembly
1 parent 4f43ece commit b8cc733

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎src/inline-assembly.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ format_string := STRING_LITERAL / RAW_STRING_LITERAL
5454
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
5555
reg_spec := <register class> / "\"" <explicit register> "\""
5656
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
57-
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr
57+
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr>
5858
clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
5959
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
6060
options := "options(" option *("," option) [","] ")"
@@ -174,14 +174,18 @@ r[asm.operand-type.supported-operands.sym]
174174
- A mangled symbol name referring to the item is substituted into the asm template string.
175175
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
176176
- `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.
177+
* `const <expr>`
178+
- `<expr>` must be an integer constant expression. This expression follows the same rules as inline `const` blocks.
179+
- The type of the expression may be any integer type, but defaults to `i32` just like integer literals.
180+
- The value of the expression is formatted as a string and substituted directly into the asm template string.
177181

178182
r[asm.operand-type.left-to-right]
179183
Operand expressions are evaluated from left to right, just like function call arguments.
180184
After the `asm!` has executed, outputs are written to in left to right order.
181185
This is significant if two outputs point to the same place: that place will contain the value of the rightmost output.
182186

183187
r[asm.operand-type.global_asm-restriction]
184-
Since `global_asm!` exists outside a function, it can only use `sym` operands.
188+
Since `global_asm!` exists outside a function, it can only use `sym` and `const` operands.
185189

186190
## Register operands
187191

0 commit comments

Comments
 (0)
Please sign in to comment.