Skip to content

Instantly share code, notes, and snippets.

@mikhail-chystsiakou
Created March 20, 2017 18:45
Show Gist options
  • Save mikhail-chystsiakou/323622361feadc37f693505ee083ea3a to your computer and use it in GitHub Desktop.
Save mikhail-chystsiakou/323622361feadc37f693505ee083ea3a to your computer and use it in GitHub Desktop.
lab1 apc
.model SMALL
.386
.data
EXTRN _begin:DWORD
EXTRN _end:DWORD
EXTRN _step:DWORD
EXTRN _x:DWORD
EXTRN _f:DWORD
tmp dw 0
.code
PUBLIC _asmCall
_asmCall PROC C
finit; // initializig fpu
fld _end; // right border end;
fld _x; // current value end;x
loop_start:
fcom; // check if out of range
fstsw tmp; // get flags to ax
mov ax, tmp
and ah, 01000101b; // check if no
jz loop_end
fld1; // end;x;1
fld _x; // end;x;1;x
fsqrt; // end;x;1;sqrt(x)
fadd; // end;x;1+sqrt(x)
fcos; // end;x;cos(1+sqrt(x))
fsin; // end;x;sin(cos(1+sqrt(x)))
fld _f; // end;x;sin(cos(1+sqrt(x)));f
fadd; // end;x;sin(cos(1+sqrt(x)))+f
fstp _f; // end;x
fadd _step; // next step
fst _x; // refresh x
jmp loop_start
loop_end:
fwait
push eax
mov eax, 0FFFFFFh
pop eax
ret
_asmCall ENDP
END
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
extern void asmCall();
float begin = 0;
float end = 9000;
float step = 0.1;
float x = 0;
float f = 0;
int main() {
clock_t beginTick, endTick;
printf("Ok go\n");
beginTick = clock();
asmCall();
endTick = clock();
printf("Asm time: %f\n", (endTick - beginTick)/CLK_TCK);
printf("Asm result: %f\n", f);
beginTick = clock();
for(x = begin, f = 0; x <= end; x+=step )
{
f += sin(cos(sqrt(x) + 1));
}
endTick = clock();
printf("C time: %f\n", (endTick - beginTick)/CLK_TCK);
printf("C result: %f\n", f);
return 0;
}
Закинуть исходники в bin.
Скомпилить через "bcc -ms c.c a.a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment