Skip to content

Instantly share code, notes, and snippets.

@ifknot
Last active February 1, 2023 22:38
Show Gist options
  • Save ifknot/4cc1d260f5eb140b4985cd5a45955b75 to your computer and use it in GitHub Desktop.
Save ifknot/4cc1d260f5eb140b4985cd5a45955b75 to your computer and use it in GitHub Desktop.
double precision sum an array single precision floats assembly language 8087 x87 NPX FPU math coprocessor
double sum_array_float(const float* array, uint16_t count) {
double sum;
__asm {
.8086
.8087
mov cx, count
jcxz END
lds si, array ; ds:[si] points to array of floats size cx
fldz
ADD_LOOP:
fadd dword ptr [si] ; dword is 32 bit single precision float
add si, 4 ; IEEE float single precision is 4 bytes
loop ADD_LOOP
END:
fstp sum
fwait ; be sure 8087 is done
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment