Skip to content

Commit 8ae391d

Browse files
committed
add the const operand to docs for inline assembly
1 parent 8c789ff commit 8ae391d

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
@@ -46,7 +46,7 @@ format_string := STRING_LITERAL / RAW_STRING_LITERAL
4646
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
4747
reg_spec := <register class> / "\"" <explicit register> "\""
4848
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
49-
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr
49+
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr>
5050
clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
5151
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
5252
options := "options(" option *("," option) [","] ")"
@@ -129,12 +129,16 @@ Several types of operands are supported:
129129
- A mangled symbol name referring to the item is substituted into the asm template string.
130130
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
131131
- `<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.
132+
* `const <expr>`
133+
- `<expr>` must be an integer constant expression. This expression follows the same rules as inline `const` blocks.
134+
- The type of the expression may be any integer type, but defaults to `i32` just like integer literals.
135+
- The value of the expression is formatted as a string and substituted directly into the asm template string.
132136

133137
Operand expressions are evaluated from left to right, just like function call arguments.
134138
After the `asm!` has executed, outputs are written to in left to right order.
135139
This is significant if two outputs point to the same place: that place will contain the value of the rightmost output.
136140

137-
Since `global_asm!` exists outside a function, it can only use `sym` operands.
141+
Since `global_asm!` exists outside a function, it can only use `sym` and `const` operands.
138142

139143
## Register operands
140144

0 commit comments

Comments
 (0)