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
Copy file name to clipboardExpand all lines: src/doc/unstable-book/src/library-features/asm.md
+17-17
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ Inline assembly is currently supported on the following architectures:
34
34
35
35
Let us start with the simplest possible example:
36
36
37
-
```rust
37
+
```rust,allow_fail
38
38
#![feature(asm)]
39
39
unsafe {
40
40
asm!("nop");
@@ -51,7 +51,7 @@ in the first argument of the `asm!` macro as a string literal.
51
51
Now inserting an instruction that does nothing is rather boring. Let us do something that
52
52
actually acts on data:
53
53
54
-
```rust
54
+
```rust,allow_fail
55
55
#![feature(asm)]
56
56
let x: u64;
57
57
unsafe {
@@ -73,7 +73,7 @@ the template and will read the variable from there after the inline assembly fin
73
73
74
74
Let us see another example that also uses an input:
75
75
76
-
```rust
76
+
```rust,allow_fail
77
77
#![feature(asm)]
78
78
let i: u64 = 3;
79
79
let o: u64;
@@ -113,7 +113,7 @@ readability, and allows reordering instructions without changing the argument or
113
113
114
114
We can further refine the above example to avoid the `mov` instruction:
115
115
116
-
```rust
116
+
```rust,allow_fail
117
117
#![feature(asm)]
118
118
let mut x: u64 = 3;
119
119
unsafe {
@@ -127,7 +127,7 @@ This is different from specifying an input and output separately in that it is g
127
127
128
128
It is also possible to specify different variables for the input and output parts of an `inout` operand:
129
129
130
-
```rust
130
+
```rust,allow_fail
131
131
#![feature(asm)]
132
132
let x: u64 = 3;
133
133
let y: u64;
@@ -149,7 +149,7 @@ There is also a `inlateout` variant of this specifier.
149
149
150
150
Here is an example where `inlateout`*cannot* be used:
151
151
152
-
```rust
152
+
```rust,allow_fail
153
153
#![feature(asm)]
154
154
let mut a: u64 = 4;
155
155
let b: u64 = 4;
@@ -170,7 +170,7 @@ Here the compiler is free to allocate the same register for inputs `b` and `c` s
170
170
171
171
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
172
172
173
-
```rust
173
+
```rust,allow_fail
174
174
#![feature(asm)]
175
175
let mut a: u64 = 4;
176
176
let b: u64 = 4;
@@ -189,7 +189,7 @@ Therefore, Rust inline assembly provides some more specific constraint specifier
189
189
While `reg` is generally available on any architecture, these are highly architecture specific. E.g. for x86 the general purpose registers `eax`, `ebx`, `ecx`, `edx`, `ebp`, `esi`, and `edi`
190
190
among others can be addressed by their name.
191
191
192
-
```rust,no_run
192
+
```rust,allow_fail,no_run
193
193
#![feature(asm)]
194
194
let cmd = 0xd1;
195
195
unsafe {
@@ -205,7 +205,7 @@ Note that unlike other operand types, explicit register operands cannot be used
205
205
206
206
Consider this example which uses the x86 `mul` instruction:
207
207
208
-
```rust
208
+
```rust,allow_fail
209
209
#![feature(asm)]
210
210
fn mul(a: u64, b: u64) -> u128 {
211
211
let lo: u64;
@@ -241,7 +241,7 @@ This state is generally referred to as being "clobbered".
241
241
We need to tell the compiler about this since it may need to save and restore this state
242
242
around the inline assembly block.
243
243
244
-
```rust
244
+
```rust,allow_fail
245
245
#![feature(asm)]
246
246
let ebx: u32;
247
247
let ecx: u32;
@@ -271,7 +271,7 @@ However we still need to tell the compiler that `eax` and `edx` have been modifi
271
271
272
272
This can also be used with a general register class (e.g. `reg`) to obtain a scratch register for use inside the asm code:
273
273
274
-
```rust
274
+
```rust,allow_fail
275
275
#![feature(asm)]
276
276
// Multiply x by 6 using shifts and adds
277
277
let mut x: u64 = 4;
@@ -293,7 +293,7 @@ assert_eq!(x, 4 * 6);
293
293
A special operand type, `sym`, allows you to use the symbol name of a `fn` or `static` in inline assembly code.
294
294
This allows you to call a function or access a global variable without needing to keep its address in a register.
295
295
296
-
```rust
296
+
```rust,allow_fail
297
297
#![feature(asm)]
298
298
extern "C" fn foo(arg: i32) {
299
299
println!("arg = {}", arg);
@@ -335,7 +335,7 @@ By default the compiler will always choose the name that refers to the full regi
335
335
336
336
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
337
337
338
-
```rust
338
+
```rust,allow_fail
339
339
#![feature(asm)]
340
340
let mut x: u16 = 0xab;
341
341
@@ -360,8 +360,8 @@ You have to manually use the memory address syntax specified by the respectively
360
360
For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]`
@@ -378,7 +378,7 @@ The compiler is allowed to instantiate multiple copies an `asm!` block, for exam
378
378
379
379
Moreover, due to [an llvm bug], you shouldn't use labels exclusively made of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values.
380
380
381
-
```rust
381
+
```rust,allow_fail
382
382
#![feature(asm)]
383
383
384
384
let mut a = 0;
@@ -415,7 +415,7 @@ By default, an inline assembly block is treated the same way as an external FFI
415
415
416
416
Let's take our previous example of an `add` instruction:
0 commit comments