asm2: example

This commit is contained in:
KoroLion 2020-12-02 15:18:15 +03:00
parent b39f224ee7
commit e9923eeba1
7 changed files with 40 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.out
*.o

View File

@ -0,0 +1 @@
nasm sum.asm -f elf && gcc main.c sum.o -m32

View 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;
}

View 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