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
+14-14
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ cannot be otherwise achieved. Accessing low level hardware primitives, e.g. in k
24
24
25
25
Let us start with the simplest possible example:
26
26
27
-
```rust
27
+
```rust,allow_fail
28
28
# #![feature(asm)]
29
29
unsafe {
30
30
asm!("nop");
@@ -41,7 +41,7 @@ in the first argument of the `asm!` macro as a string literal.
41
41
Now inserting an instruction that does nothing is rather boring. Let us do something that
42
42
actually acts on data:
43
43
44
-
```rust
44
+
```rust,allow_fail
45
45
# #![feature(asm)]
46
46
let x: u64;
47
47
unsafe {
@@ -63,7 +63,7 @@ the template and will read the variable from there after the inline assembly fin
63
63
64
64
Let us see another example that also uses an input:
65
65
66
-
```rust
66
+
```rust,allow_fail
67
67
# #![feature(asm)]
68
68
let i: u64 = 3;
69
69
let o: u64;
@@ -95,7 +95,7 @@ readability, and allows reordering instructions without changing the argument or
95
95
96
96
We can further refine the above example to avoid the `mov` instruction:
97
97
98
-
```rust
98
+
```rust,allow_fail
99
99
# #![feature(asm)]
100
100
let mut x: u64 = 3;
101
101
unsafe {
@@ -109,7 +109,7 @@ This is different from specifying an input and output separately in that it is g
109
109
110
110
It is also possible to specify different variables for the input and output parts of an `inout` operand:
111
111
112
-
```rust
112
+
```rust,allow_fail
113
113
# #![feature(asm)]
114
114
let x: u64 = 3;
115
115
let y: u64;
@@ -131,7 +131,7 @@ There is also a `inlateout` variant of this specifier.
131
131
132
132
Here is an example where `inlateout`*cannot* be used:
133
133
134
-
```rust
134
+
```rust,allow_fail
135
135
# #![feature(asm)]
136
136
let mut a: u64 = 4;
137
137
let b: u64 = 4;
@@ -149,7 +149,7 @@ Here the compiler is free to allocate the same register for inputs `b` and `c` s
149
149
150
150
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
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;
@@ -168,7 +168,7 @@ Therefore, Rust inline assembly provides some more specific constraint specifier
168
168
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`
169
169
among others can be addressed by their name.
170
170
171
-
```rust,no_run
171
+
```rust,allow_fail,no_run
172
172
# #![feature(asm)]
173
173
let cmd = 0xd1;
174
174
unsafe {
@@ -184,7 +184,7 @@ Note that unlike other operand types, explicit register operands cannot be used
184
184
185
185
Consider this example which uses the x86 `mul` instruction:
186
186
187
-
```rust
187
+
```rust,allow_fail
188
188
# #![feature(asm)]
189
189
fn mul(a: u64, b: u64) -> u128 {
190
190
let lo: u64;
@@ -220,7 +220,7 @@ This state is generally referred to as being "clobbered".
220
220
We need to tell the compiler about this since it may need to save and restore this state
221
221
around the inline assembly block.
222
222
223
-
```rust
223
+
```rust,allow_fail
224
224
# #![feature(asm)]
225
225
let ebx: u32;
226
226
let ecx: u32;
@@ -250,7 +250,7 @@ However we still need to tell the compiler that `eax` and `edx` have been modifi
250
250
251
251
This can also be used with a general register class (e.g. `reg`) to obtain a scratch register for use inside the asm code:
252
252
253
-
```rust
253
+
```rust,allow_fail
254
254
# #![feature(asm)]
255
255
// Multiply x by 6 using shifts and adds
256
256
let mut x: u64 = 4;
@@ -270,7 +270,7 @@ assert_eq!(x, 4 * 6);
270
270
A special operand type, `sym`, allows you to use the symbol name of a `fn` or `static` in inline assembly code.
271
271
This allows you to call a function or access a global variable without needing to keep its address in a register.
272
272
273
-
```rust
273
+
```rust,allow_fail
274
274
# #![feature(asm)]
275
275
extern "C" fn foo(arg: i32) {
276
276
println!("arg = {}", arg);
@@ -306,7 +306,7 @@ By default the compiler will always choose the name that refers to the full regi
306
306
307
307
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
308
308
309
-
```rust
309
+
```rust,allow_fail
310
310
# #![feature(asm)]
311
311
let mut x: u16 = 0xab;
312
312
@@ -330,7 +330,7 @@ By default, an inline assembly block is treated the same way as an external FFI
330
330
331
331
Let's take our previous example of an `add` instruction:
0 commit comments