asm2: example
This commit is contained in:
parent
b39f224ee7
commit
e9923eeba1
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.out
|
||||
*.o
|
1
asm2/example_c_asm_and_coproc/compile.sh
Normal file
1
asm2/example_c_asm_and_coproc/compile.sh
Normal file
|
@ -0,0 +1 @@
|
|||
nasm sum.asm -f elf && gcc main.c sum.o -m32
|
18
asm2/example_c_asm_and_coproc/main.c
Normal file
18
asm2/example_c_asm_and_coproc/main.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
Copyright 2020 KoroLion (github.com/KoroLion)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
float sum(float a, float b);
|
||||
|
||||
int main() {
|
||||
float a, b;
|
||||
scanf("%f %f", &a, &b);
|
||||
|
||||
float c = sum(a, b);
|
||||
|
||||
printf("%f\n", c);
|
||||
|
||||
return 0;
|
||||
}
|
19
asm2/example_c_asm_and_coproc/sum.asm
Normal file
19
asm2/example_c_asm_and_coproc/sum.asm
Normal file
|
@ -0,0 +1,19 @@
|
|||
; Copyright 2020 KoroLion (github.com/KoroLion)
|
||||
|
||||
global sum
|
||||
|
||||
section .data
|
||||
section .bss
|
||||
temp: resb 4
|
||||
|
||||
section .text
|
||||
|
||||
; sum(x, y)
|
||||
sum:
|
||||
finit
|
||||
fld dword [esp + 4] ; = x
|
||||
fadd dword [esp + 8] ; += y
|
||||
fst dword [temp] ; [temp] = st0
|
||||
|
||||
mov eax, [temp]
|
||||
ret
|
Loading…
Reference in New Issue
Block a user