Skip to content

Commit 6194d7e

Browse files
authored
Rollup merge of #76675 - lzutao:asm_doc, r=Amanieu
Small improvements to asm documentation Save people from searching and reading tons of comments in tracking issues.
2 parents d1b0504 + e82be71 commit 6194d7e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/doc/unstable-book/src/library-features/asm.md

+19
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ The `h` modifier will emit the register name for the high byte of that register
345345

346346
If you use a smaller data type (e.g. `u16`) with an operand and forget the use template modifiers, the compiler will emit a warning and suggest the correct modifier to use.
347347

348+
## Memory address operands
349+
350+
Sometimes assembly instructions require operands passed via memory addresses/memory locations.
351+
You have to manually use the memory address syntax specified by the respectively architectures.
352+
For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]`
353+
to indicate they are memory operands:
354+
355+
```rust,allow_fail
356+
# #![feature(asm, llvm_asm)]
357+
# fn load_fpu_control_word(control: u16) {
358+
unsafe {
359+
asm!("fldcw [{}]", in(reg) &control, options(nostack));
360+
361+
// Previously this would have been written with the deprecated `llvm_asm!` like this
362+
llvm_asm!("fldcw $0" :: "m" (control) :: "volatile");
363+
}
364+
# }
365+
```
366+
348367
## Options
349368

350369
By default, an inline assembly block is treated the same way as an external FFI function call with a custom calling convention: it may read/write memory, have observable side effects, etc. However in many cases, it is desirable to give the compiler more information about what the assembly code is actually doing so that it can optimize better.

src/doc/unstable-book/src/library-features/llvm-asm.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ specify some extra info about the inline assembly:
159159

160160
Current valid options are:
161161

162-
1. *volatile* - specifying this is analogous to
162+
1. `volatile` - specifying this is analogous to
163163
`__asm__ __volatile__ (...)` in gcc/clang.
164-
2. *alignstack* - certain instructions expect the stack to be
164+
2. `alignstack` - certain instructions expect the stack to be
165165
aligned a certain way (i.e. SSE) and specifying this indicates to
166166
the compiler to insert its usual stack alignment code
167-
3. *intel* - use intel syntax instead of the default AT&T.
167+
3. `intel` - use intel syntax instead of the default AT&T.
168168

169169
```rust
170170
# #![feature(llvm_asm)]

0 commit comments

Comments
 (0)