1- # ` asm `
1+ # ` llvm_asm `
22
3- The tracking issue for this feature is: [ #29722 ]
3+ The tracking issue for this feature is: [ #70173 ]
44
5- [ #29722 ] : https://github.com/rust-lang/rust/issues/29722
5+ [ #70173 ] : https://github.com/rust-lang/rust/issues/70173
66
77------------------------
88
99For extremely low-level manipulations and performance reasons, one
1010might wish to control the CPU directly. Rust supports using inline
11- assembly to do this via the ` asm !` macro.
11+ assembly to do this via the ` llvm_asm !` macro.
1212
1313``` rust,ignore
14- asm !(assembly template
14+ llvm_asm !(assembly template
1515 : output operands
1616 : input operands
1717 : clobbers
1818 : options
1919 );
2020```
2121
22- Any use of ` asm ` is feature gated (requires ` #![feature(asm )] ` on the
22+ Any use of ` llvm_asm ` is feature gated (requires ` #![feature(llvm_asm )] ` on the
2323crate to allow) and of course requires an ` unsafe ` block.
2424
2525> ** Note** : the examples here are given in x86/x86-64 assembly, but
@@ -31,12 +31,12 @@ The `assembly template` is the only required parameter and must be a
3131literal string (i.e. ` "" ` )
3232
3333``` rust
34- #![feature(asm )]
34+ #![feature(llvm_asm )]
3535
3636#[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
3737fn foo () {
3838 unsafe {
39- asm ! (" NOP" );
39+ llvm_asm ! (" NOP" );
4040 }
4141}
4242
@@ -51,16 +51,16 @@ fn main() {
5151}
5252```
5353
54- (The ` feature(asm ) ` and ` #[cfg] ` s are omitted from now on.)
54+ (The ` feature(llvm_asm ) ` and ` #[cfg] ` s are omitted from now on.)
5555
5656Output operands, input operands, clobbers and options are all optional
5757but you must add the right number of ` : ` if you skip them:
5858
5959``` rust
60- # #![feature(asm )]
60+ # #![feature(llvm_asm )]
6161# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
6262# fn main () { unsafe {
63- asm ! (" xor %eax, %eax"
63+ llvm_asm ! (" xor %eax, %eax"
6464 :
6565 :
6666 : " eax"
@@ -73,10 +73,10 @@ asm!("xor %eax, %eax"
7373Whitespace also doesn't matter:
7474
7575``` rust
76- # #![feature(asm )]
76+ # #![feature(llvm_asm )]
7777# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
7878# fn main () { unsafe {
79- asm ! (" xor %eax, %eax" :: : " eax" );
79+ llvm_asm ! (" xor %eax, %eax" :: : " eax" );
8080# } }
8181# #[cfg(not(any(target_arch = " x86" , target_arch = " x86_64" )))]
8282# fn main () {}
@@ -89,12 +89,12 @@ Input and output operands follow the same format: `:
8989expressions must be mutable lvalues, or not yet assigned:
9090
9191``` rust
92- # #![feature(asm )]
92+ # #![feature(llvm_asm )]
9393# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
9494fn add (a : i32 , b : i32 ) -> i32 {
9595 let c : i32 ;
9696 unsafe {
97- asm ! (" add $2, $0"
97+ llvm_asm ! (" add $2, $0"
9898 : " =r" (c )
9999 : " 0" (a ), " r" (b )
100100 );
@@ -116,11 +116,11 @@ operand. This is useful for very low level programming, where
116116which register you use is important:
117117
118118``` rust
119- # #![feature(asm )]
119+ # #![feature(llvm_asm )]
120120# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
121121# unsafe fn read_byte_in (port : u16 ) -> u8 {
122122let result : u8 ;
123- asm ! (" in %dx, %al" : " ={al}" (result ) : " {dx}" (port ));
123+ llvm_asm ! (" in %dx, %al" : " ={al}" (result ) : " {dx}" (port ));
124124result
125125# }
126126```
@@ -133,11 +133,11 @@ compiler not to assume any values loaded into those registers will
133133stay valid.
134134
135135``` rust
136- # #![feature(asm )]
136+ # #![feature(llvm_asm )]
137137# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
138138# fn main () { unsafe {
139139// Put the value 0x200 in eax:
140- asm ! (" mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : " eax" );
140+ llvm_asm ! (" mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : " eax" );
141141# } }
142142# #[cfg(not(any(target_arch = " x86" , target_arch = " x86_64" )))]
143143# fn main () {}
@@ -167,12 +167,12 @@ Current valid options are:
1671673 . * intel* - use intel syntax instead of the default AT&T.
168168
169169``` rust
170- # #![feature(asm )]
170+ # #![feature(llvm_asm )]
171171# #[cfg(any(target_arch = " x86" , target_arch = " x86_64" ))]
172172# fn main () {
173173let result : i32 ;
174174unsafe {
175- asm ! (" mov eax, 2" : " ={eax}" (result ) : : : " intel" )
175+ llvm_asm ! (" mov eax, 2" : " ={eax}" (result ) : : : " intel" )
176176}
177177println! (" eax is currently {}" , result );
178178# }
@@ -182,12 +182,12 @@ println!("eax is currently {}", result);
182182
183183## More Information
184184
185- The current implementation of the ` asm !` macro is a direct binding to [ LLVM's
185+ The current implementation of the ` llvm_asm !` macro is a direct binding to [ LLVM's
186186inline assembler expressions] [ llvm-docs ] , so be sure to check out [ their
187187documentation as well] [ llvm-docs ] for more information about clobbers,
188188constraints, etc.
189189
190190[ llvm-docs ] : http://llvm.org/docs/LangRef.html#inline-assembler-expressions
191191
192192If you need more power and don't mind losing some of the niceties of
193- ` asm !` , check out [ global_asm] ( global-asm.md ) .
193+ ` llvm_asm !` , check out [ global_asm] ( global-asm.md ) .
0 commit comments