You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -259,12 +270,14 @@ This can also be used with a general register class (e.g. `reg`) to obtain a scr
259
270
// Multiply x by 6 using shifts and adds
260
271
letmutx:u64=4;
261
272
unsafe {
262
-
asm!("
263
-
mov {tmp}, {x}
264
-
shl {tmp}, 1
265
-
shl {x}, 2
266
-
add {x}, {tmp}
267
-
", x=inout(reg) x, tmp=out(reg) _);
273
+
asm!(
274
+
"mov {tmp}, {x}",
275
+
"shl {tmp}, 1",
276
+
"shl {x}, 2",
277
+
"add {x}, {tmp}",
278
+
x=inout(reg) x,
279
+
tmp=out(reg) _,
280
+
);
268
281
}
269
282
assert_eq!(x, 4*6);
270
283
```
@@ -359,6 +372,7 @@ See the reference for the full list of available options and their effects.
359
372
360
373
Inline assembler is implemented as an unsafe macro `asm!()`.
361
374
The first argument to this macro is a template string literal used to build the final assembly.
375
+
Additional template string literal arguments may be provided; all of the template string arguments are interpreted as if concatenated into a single template string with `\n` between them.
362
376
The following arguments specify input and output operands.
363
377
When required, options are specified as the final argument.
The macro will initially be supported only on ARM, AArch64, x86, x86-64 and RISC-V targets. Support for more targets may be added in the future. The compiler will emit an error if `asm!` is used on an unsupported target.
The assembler template uses the same syntax as [format strings][format-syntax] (i.e. placeholders are specified by curly braces). The corresponding arguments are accessed in order, by index, or by name. However, implicit named arguments (introduced by [RFC #2795][rfc-2795]) are not supported.
385
399
400
+
An `asm!` invocation may have one or more template string arguments; an `asm!` with multiple template string arguments is treated as if all the strings were concatenated with a `\n` between them. The expected usage is for each template string argument to correspond to a line of assembly code. All template string arguments must appear before any other arguments.
401
+
386
402
As with format strings, named arguments must appear after positional arguments. Explicit register operands must appear at the end of the operand list, after named arguments if any.
387
403
388
404
Explicit register operands cannot be used by placeholders in the template string. All other named and positional operands must appear at least once in the template string, otherwise a compiler error is generated.
@@ -1007,6 +1023,12 @@ Including the name of the target architecture as part of the `asm!` invocation c
1007
1023
1008
1024
The operands could be placed before the template string, which could make the asm easier to read in some cases. However we decided against it because the benefits are small and the syntax would no longer mirror that of Rust format string.
1009
1025
1026
+
## Operands interleaved with template string arguments
1027
+
1028
+
An asm directive could contain a series of template string arguments, each followed by the operands referenced in that template string argument. This could potentially simplify long blocks of assembly. However, this could introduce significant complexity and difficulty of reading, due to the numbering of positional arguments, and the possibility of referencing named or numbered arguments other than those that appear grouped with a given template string argument.
1029
+
1030
+
Experimentation with such mechanisms could take place in wrapper macros around `asm!`, rather than in `asm!` itself.
1031
+
1010
1032
# Prior art
1011
1033
[prior-art]: #prior-art
1012
1034
@@ -1043,7 +1065,9 @@ GCC supports passing C labels (the ones used with `goto`) to an inline asm block
1043
1065
This could be supported by allowing code blocks to be specified as operand types. The following code will print `a` if the input value is `42`, or print `b` otherwise.
0 commit comments