Created
October 4, 2016 20:19
-
-
Save joastbg/c00524e8b888bedb9fedd24be008dd52 to your computer and use it in GitHub Desktop.
Fun with x87 instructions using inline assembly (Intel syntax)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ fun.cc -masm=intel | |
float fpzero = 0; | |
unsigned long pfpzero = (unsigned long)&fpzero; | |
__asm__ volatile("xorps xmm1, xmm1"); | |
__asm__ volatile("fldpi"); // load PI | |
__asm__ volatile("fchs"); // change sign | |
__asm__ volatile("fst dword ptr [%0]":"=&r"(pfpzero)); | |
// this should be -3.14159... | |
std::cout << fpzero << std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment