Created
July 6, 2017 19:53
-
-
Save clausecker/b0ceb54c42a6d4b0add1684ecc3abf80 to your computer and use it in GitHub Desktop.
Compute exp() in i386 assembly
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
| .text | |
| .globl exp | |
| .type exp,@function | |
| .align 16 | |
| exp: | |
| fldt 4(%esp) # x | |
| fldl2e # log2(e) x | |
| fmulp # x' (= log2(e) * x) | |
| fld %st(0) # x' x' | |
| frndint # round(x') x' | |
| fsubr %st(0),%st(1) # round(x') x'-round(x') | |
| fxch # x'-round(x') round(x') | |
| f2xm1 # 2^(x'-round(x'))-1 round(x') | |
| fld1 # 1 2^(x'-round(x'))-1 round(x') | |
| faddp # 2^(x'-round(x')) round(x') | |
| fscale # 2^(x'-round(x'))*2^round(x') (= 2^x' = e^x) round(x') | |
| fstp %st(1) # e^x | |
| ret | |
| .size exp,.-exp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment