Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Inline assembler
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Motivation and alternatives == The embedding of assembly language code is usually done for one of these reasons:<ref name=gcc-dont>{{cite web |title=DontUseInlineAsm |url=https://gcc.gnu.org/wiki/DontUseInlineAsm |website=GCC Wiki |access-date=21 January 2020}}</ref> * [[Optimization (computer science)|Optimization]]: Programmers can use assembly language code to implement the most performance-sensitive parts of their program's [[algorithm|algorithms]], code that is apt to be more efficient than what might otherwise be generated by the compiler. * Access to processor-specific [[Instruction (computer science)|instruction]]s: Most processors offer special instructions, such as [[Compare-and-swap|Compare and Swap]] and [[Test-and-set|Test and Set]] instructions which may be used to construct [[Semaphore (programming)|semaphores]] or other synchronization and locking primitives. Nearly every modern processor has these or similar instructions, as they are necessary to implement [[computer multitasking|multitasking]]. Examples of specialized instructions are found in the [[SPARC]] [[Visual Instruction Set|VIS]], [[Intel]] [[MMX (instruction set)|MMX]] and [[Streaming SIMD Extensions|SSE]], and [[Motorola]] [[Altivec]] [[instruction set]]s. * Access to special [[calling convention]]s not yet supported by the compiler. * [[System call]]s and interrupts: High-level languages rarely have a direct facility to make arbitrary system calls, so assembly code is used. Direct interrupts are even more rarely supplied. * To emit special directives for the linker or assembler, for example to change sectioning, macros, or to make symbol aliases. On the other hand, inline assembler poses a direct problem for the compiler itself as it complicates the analysis of what is done to each variable, a key part of register allocation.<ref>{{cite web |last1=Striegel |first1=Ben |title="To a compiler, a blob of inline assembly is like a slap in the face."|url=https://www.reddit.com/r/rust/comments/eo9pks/the_asm_working_group_has_submitted_their_first/feb7yy4/ |website=Reddit |date=13 January 2020 |access-date=15 January 2020}}</ref> This means the performance might actually decrease. Inline assembler also complicates future porting and maintenance of a program.<ref name=gcc-dont/> Alternative facilities are often provided as a way to simplify the work for both the compiler and the programmer. [[Intrinsic function]]s for special instructions are provided by most compilers and C-function wrappers for arbitrary system calls are available on every [[Unix]] platform.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)