Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd1972f
commit de9f686
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
# Call the sincos glibc C function | ||
|
||
# C | ||
|
||
```c | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
int main ( int argc , char * argv[] ) | ||
{ | ||
double a ; | ||
double b ; | ||
double c ; | ||
|
||
a = atof( argv[1] ) ; | ||
|
||
sincos( a , &b , &c ) ; | ||
|
||
printf( "%f %f\n" , b , c ) ; | ||
|
||
return 0 ; | ||
} | ||
``` | ||
# Assembly | ||
```s | ||
.include "utils.s" | ||
global_text main | ||
prepare_stack | ||
.set offset , 0 | ||
stack_allocate ARGV , 8 | ||
stack_allocate A , 8 | ||
stack_allocate B , 8 | ||
stack_allocate C , 8 | ||
mov %rsi , ARGV(%rbp) | ||
ref8 ARGV , 1 , %rdi | ||
call atof ; | ||
movsd %xmm0 , A(%rbp) | ||
movsd A(%rbp) , %xmm0 | ||
lea B(%rbp) , %rdi | ||
lea C(%rbp) , %rsi | ||
call sincos | ||
print_double B(%rbp) | ||
print_literal_string " " | ||
print_double C(%rbp) | ||
print_nl | ||
return_integer $0 | ||
``` | ||
|
||
# Assemble and run | ||
|
||
$ gcc sincos.s -lm && ./a.out 0.0 | ||
0.000000 1.000000 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Call the sincos glibc C function | ||
|
||
# C | ||
|
||
```c | ||
#include file="sincos.c" | ||
``` | ||
|
||
# Assembly | ||
|
||
```s | ||
#include file="sincos.s" | ||
``` | ||
|
||
# Assemble and run | ||
|
||
$ gcc sincos.s -lm && ./a.out 0.0 | ||
0.000000 1.000000 |