Skip to content

Commit bd9ad8e

Browse files
committed
Add example of inline assembly
1 parent 480f6d4 commit bd9ad8e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/inline-assembly.md

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ It can be used to embed handwritten assembly in the assembly output generated by
66
[`asm!`]: ../core/arch/macro.asm.html
77
[`global_asm!`]: ../core/arch/macro.global_asm.html
88

9+
```rust
10+
#![feature(asm)]
11+
// Multiply x by 6 using shifts and adds
12+
let mut x: u64 = 4;
13+
unsafe {
14+
asm!(
15+
"mov {tmp}, {x}",
16+
"shl {tmp}, 1",
17+
"shl {x}, 2",
18+
"add {x}, {tmp}",
19+
x = inout(reg) x,
20+
tmp = out(reg) _,
21+
);
22+
}
23+
assert_eq!(x, 4 * 6);
24+
```
25+
926
The following ABNF specifies the general syntax:
1027

1128
```text

0 commit comments

Comments
 (0)