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!
=== Processor-specific instruction in D === This example of inline assembly from the [[D programming language]] shows code that computes the tangent of x using the [[x86]]'s [[floating point unit|FPU]] ([[x87]]) instructions. <syntaxhighlight lang="d"> // Compute the tangent of x real tan(real x) { asm { fld x[EBP] ; // load x fxam ; // test for oddball values fstsw AX ; sahf ; jc trigerr ; // C0 = 1: x is NAN, infinity, or empty // 387's can handle denormals SC18: fptan ; fstp ST(0) ; // dump X, which is always 1 fstsw AX ; sahf ; // if (!(fp_status & 0x20)) goto Lret jnp Lret ; // C2 = 1: x is out of range, do argument reduction fldpi ; // load pi fxch ; SC17: fprem1 ; // reminder (partial) fstsw AX ; sahf ; jp SC17 ; // C2 = 1: partial reminder, need to loop fstp ST(1) ; // remove pi from stack jmp SC18 ; } trigerr: return real.nan; Lret: // No need to manually return anything as the value is already on FP stack ; } </syntaxhighlight> The {{tt|fstsw-sahf}} followed by conditional jump idiom is used to access the x87 FPU status word bits C0 and C2. {{tt|fstsw}} stores the status in a general-purpose register; sahf sets the [[FLAGS register]] to the higher 8 bits of the register; and the jump is used to judge on whatever flag bit that happens to correspond to the FPU status bit.<ref>{{cite web |title=FSTSW/FNSTSW β Store x87 FPU Status Word |url=https://www.felixcloutier.com/x86/fstsw:fnstsw |quote=The FNSTSW AX form of the instruction is used primarily in conditional branching...}}</ref>
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)