study_public/asm2/example_c_asm_and_coproc/utils.asm

37 lines
566 B
NASM
Raw Normal View History

2020-12-03 15:56:26 +03:00
; Copyright 2020 KoroLion (github.com/KoroLion)
global sum
global fx
section .data
section .bss
temp: resb 4
section .text
; float sum(float x, float y)
; return x + y
sum:
finit
fld dword [esp + 4] ; st0 = x
fadd dword [esp + 8] ; st0 += y
ret ; returns st0 to c
; float fx(float x)
; return 1 / (x + 2)
fx:
; st1
fld dword [esp + 4] ; st1 = x
mov dword [temp], 2
fiadd dword [temp] ; st1 += 2
; st0
mov dword [temp], 1
fild dword [temp] ; st0 = 1
fdiv st0, st1 ; st0 /= st1
ret ; returns st0 to c