< -->

Program Math_Processor;
{$N+,E-,G+}
{$L C:\PROGRA~2\BP70\BIN\EGAVGA.OBJ}
{Координатные плоскости (x(t), y(t)), (x, t), (y, t)}
{!Возможность  включения сумм <- команды условные и циклич.}
{Выбор: использовать PutPixel или LineTo}
Uses Graph, CRT;
const
  _ = 123;{!}
  cmdMaxL = 3;
  NearAddr = $80;
  ShortAddr = $40;
  Relative = 1;
  Absol = 2;
  Conds = 4;
  Regs = 8;
type
  TCmd = record
    Code : array[0..cmdMaxL] of Byte;
    Len : Byte; {Старший Байт (80h=128) не ноль, если используется ближ. адрес}
                {байт (40h=64) не ноль, если используется короткий переход}
    Flag : Byte; {Indirect-косвенный адрес, Direct-прямой}
  end;
  Address = record
   Ofs, Seg : Integer;
  end;
{
$00 - add
$01 - sub
$02 - mul
$03 - div
$FF $xx - load  Op[xx]
$FE $xx - store Op[xx]
$10 - 1/x
$11 - sqr
$12 - sqrt
$13 - cube
$14 - cubert
$40 - exp [др основания?]    []
$41 - 10^x
$42 - 2^x
$43 - x^y
$48 - ln [по др основаниям?]
$49 - log
$4A - log2
$4B - logY(X) ? X(Y)
$20 - sin
$21 - cos
$22 - tan
$23 - cotan
$30 - asin
$31 - acos
$32 - atan
$33 - acotan
$50 - xchg [tops of stack]
$51 - sign[x]
$52 - abs[x]
$60 - load 0;
$61 - load 1;
$62 - load e;
$63 - load pi;
}
const
  MaxProcSize = 4095;{MPS-1}
  C_o = 0;
  C_n = 1;
  C_c = 2;
  C_z = 4;
  C_s = 8;
  st0 = 0;st1 = 1;st2 = 2;st3 = 3;
  st4 = 4;st5 = 5;st6 = 6;st7 = 7;
  NoReg = 8;
  NoPfx = 0;{NoPrefix}
  DS_Prefix = $3E;
  ES_Prefix = $26;
  FS_Prefix = $65;
  GS_Prefix = $64;
  CS_Prefix = $2E;
  SS_Prefix = $36;
  rep_Prefix = $F3;
  repe_Prefix = $F3;
  repne_Prefix = $F2;
  retNear = $C3;
  NOP = $90;
  fwait = $9B;

  nilcmd : TCmd = (Code:(0,0,0,0); Len:0;Flag:0);

  jmps : TCmd = (Code:($EB, 0, 0, 0); Len:1+ShortAddr; Flag:Relative);
  jmpr : TCmd = (Code:($E9, $0, $0, $0); Len:1+NearAddr; Flag: Relative);
  jmpa : TCmd = (Code:($FF, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  jxx  : TCmd = (Code:($70, $0, $0, $0); Len:1+ShortAddr; Flag: Relative+Conds);

  fdecstp: TCmd = (Code:($D9, $F6, $0, $0); Len:2; Flag: 0);
  fincstp : TCmd = (Code:($D9, $F7, $0, $0); Len:2; Flag: 0);
  ffree : TCmd = (Code:($DD, $C0, $0, $0); Len:2; Flag: Regs);
  fnop  : TCmd = (Code:($D9, $D0, $0, $0); Len:2; Flag: 0);

  fldz  : TCmd = (Code:($D9, $EE, $0, $0); Len:2; Flag: 0);
  fld1  : TCmd = (Code:($D9, $E8, $0, $0); Len:2; Flag: 0);
  fldpi  : TCmd = (Code:($D9, $EB, $0, $0); Len:2; Flag: 0);
  fldl2t  : TCmd = (Code:($D9, $E9, $0, $0); Len:2; Flag: 0);
  fldl2e  : TCmd = (Code:($D9, $EA, $0, $0); Len:2; Flag: 0);
  fldlg2  : TCmd = (Code:($D9, $EC, $0, $0); Len:2; Flag: 0);
  fldln2  : TCmd = (Code:($D9, $ED, $0, $0); Len:2; Flag: 0);
  fcompp  : TCmd = (Code:($DE, $D9, $0, $0); Len:2; Flag: 0);
  ftst  : TCmd = (Code:($D9, $E4, $0, $0); Len:2; Flag: 0);
  fucompp  : TCmd = (Code:($DA, $E9, $0, $0); Len:2; Flag: 0);
  fxam  : TCmd = (Code:($D9, $E5, $0, $0); Len:2; Flag: 0);
  fsqrt  : TCmd = (Code:($D9, $FA, $0, $0); Len:2; Flag: 0);
  fscale  : TCmd = (Code:($D9, $FD, $0, $0); Len:2; Flag: 0);
  fxtract  : TCmd = (Code:($D9, $F4, $0, $0); Len:2; Flag: 0);
  fprem  : TCmd = (Code:($D9, $F8, $0, $0); Len:2; Flag: 0);
  fprem1  : TCmd = (Code:($D9, $F5, $0, $0); Len:2; Flag: 0);
  frndint  : TCmd = (Code:($D9, $FC, $0, $0); Len:2; Flag: 0);
  fabs  : TCmd = (Code:($D9, $E1, $0, $0); Len:2; Flag: 0);
  fchs  : TCmd = (Code:($D9, $E0, $0, $0); Len:2; Flag: 0);
  fcos  : TCmd = (Code:($D9, $FF, $0, $0); Len:2; Flag: 0);
  fsin  : TCmd = (Code:($D9, $FE, $0, $0); Len:2; Flag: 0);
  fsincos  : TCmd = (Code:($D9, $FB, $0, $0); Len:2; Flag: 0);
  fptan  : TCmd = (Code:($D9, $F2, $0, $0); Len:2; Flag: 0);
  fpatan  : TCmd = (Code:($D9, $F3, $0, $0); Len:2; Flag: 0);
  f2xm1  : TCmd = (Code:($D9, $F0, $0, $0); Len:2; Flag: 0);
  fyl2x  : TCmd = (Code:($D9, $F1, $0, $0); Len:2; Flag: 0);
  fyl2xp1  : TCmd = (Code:($D9, $F9, $0, $0); Len:2; Flag: 0);
  finit  : TCmd = (Code:($9B, $DB, $E3, $0); Len:3; Flag: 0);
  fstswax  : TCmd = (Code:($9B, $DF, $E0, $0); Len:3; Flag: 0);
  fclex  : TCmd = (Code:($9B, $DB, $E2, $0); Len:3; Flag: 0);

  fld  : TCmd = (Code:($D9, $C0, $0, $0); Len:2; Flag: Regs);
  fxch  : TCmd = (Code:($D9, $C8, $0, $0); Len:2; Flag: Regs);
  fcom  : TCmd = (Code:($D8, $D0, $0, $0); Len:2; Flag: Regs);
  fcomp  : TCmd = (Code:($D8, $D8, $0, $0); Len:2; Flag: Regs);
  fucom  : TCmd = (Code:($DD, $E0, $0, $0); Len:2; Flag: Regs);
  fucomp  : TCmd = (Code:($DD, $E8, $0, $0); Len:2; Flag: Regs);
  fadd  : TCmd = (Code:($D8, $C0, $0, $0); Len:2; Flag: Regs);{st[0]<-st[i]+st[0]}
  fadd_  : TCmd = (Code:($DC, $C0, $0, $0); Len:2; Flag: Regs);{st[i]<-st[i]+st[0]}
  faddp  : TCmd = (Code:($DE, $C0, $0, $0); Len:2; Flag: Regs);
  fsub  : TCmd = (Code:($D8, $E0, $0, $0); Len:2; Flag: Regs);
  fsub_  : TCmd = (Code:($DC, $E8, $0, $0); Len:2; Flag: Regs);
  fsubr  : TCmd = (Code:($D8, $E8, $0, $0); Len:2; Flag: Regs);
  fsubr_  : TCmd = (Code:($DC, $E0, $0, $0); Len:2; Flag: Regs);
  fsubp  : TCmd = (Code:($DE, $E8, $0, $0); Len:2; Flag: Regs);
  fsubrp  : TCmd = (Code:($DE, $E0, $0, $0); Len:2; Flag: Regs);
  fmul  : TCmd = (Code:($D8, $C8, $0, $0); Len:2; Flag: Regs);
  fmul_  : TCmd = (Code:($DC, $C8, $0, $0); Len:2; Flag: Regs);
  fmulp  : TCmd = (Code:($DE, $C8, $0, $0); Len:2; Flag: Regs);
  fdiv  : TCmd = (Code:($D8, $F0, $0, $0); Len:2; Flag: Regs);
  fdiv_  : TCmd = (Code:($DC, $F8, $0, $0); Len:2; Flag: Regs);
  fdivp  : TCmd = (Code:($DE, $F8, $0, $0); Len:2; Flag: Regs);
  fdivr  : TCmd = (Code:($D8, $F8, $0, $0); Len:2; Flag: Regs);
  fdivr_  : TCmd = (Code:($DC, $F0, $0, $0); Len:2; Flag: Regs);
  fdivrp  : TCmd = (Code:($DE, $F0, $0, $0); Len:2; Flag: Regs);

  fldd  : TCmd = (Code:($0D9, $06, $0, $0); Len:2+NearAddr; Flag: Absol);{DS:[addr]}
  fldq  : TCmd = (Code:($DD, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fldt  : TCmd = (Code:($DB, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fildw  : TCmd = (Code:($DF, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fildd  : TCmd = (Code:($DB, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fildq  : TCmd = (Code:($DF, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fbldt  : TCmd = (Code:($DF, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstd  : TCmd = (Code:($D9, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstq  : TCmd = (Code:($DD, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstpd  : TCmd = (Code:($D9, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstpq  : TCmd = (Code:($DD, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstpt  : TCmd = (Code:($DB, $3E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fbstpt  : TCmd = (Code:($DF, $36, $0, $0); Len:2+NearAddr; Flag: Absol);
  fcomd  : TCmd = (Code:($D8, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  fcomq  : TCmd = (Code:($DC, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  fcompd  : TCmd = (Code:($D8, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fcompq  : TCmd = (Code:($DC, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  ficomw  : TCmd = (Code:($DE, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  ficomd  : TCmd = (Code:($DA, $16, $0, $0); Len:2+NearAddr; Flag: Absol);
  ficompw  : TCmd = (Code:($DE, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  ficompd  : TCmd = (Code:($DA, $1E, $0, $0); Len:2+NearAddr; Flag: Absol);
  faddd  : TCmd = (Code:($D8, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  faddq  : TCmd = (Code:($DC, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fiaddw  : TCmd = (Code:($DE, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fiaddd  : TCmd = (Code:($DA, $06, $0, $0); Len:2+NearAddr; Flag: Absol);
  fsubd  : TCmd = (Code:($D8, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fsubq  : TCmd = (Code:($DC, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fsubrd  : TCmd = (Code:($D8, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fsubrq  : TCmd = (Code:($DC, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fisubw  : TCmd = (Code:($DE, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fisubd  : TCmd = (Code:($DA, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fisubrw  : TCmd = (Code:($DE, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fisubrd  : TCmd = (Code:($DA, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fmuld  : TCmd = (Code:($D8, $0E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fmulq  : TCmd = (Code:($DC, $0E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fimulw  : TCmd = (Code:($DE, $0E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fimuld  : TCmd = (Code:($DA, $0E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fdivd  : TCmd = (Code:($D8, $36, $0, $0); Len:2+NearAddr; Flag: Absol);
  fdivq  : TCmd = (Code:($DC, $36, $0, $0); Len:2+NearAddr; Flag: Absol);
  fidivw  : TCmd = (Code:($DE, $36, $0, $0); Len:2+NearAddr; Flag: Absol);
  fidivd  : TCmd = (Code:($DA, $36, $0, $0); Len:2+NearAddr; Flag: Absol);
  fdivrd  : TCmd = (Code:($D8, $3E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fdivrq  : TCmd = (Code:($DC, $3E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fidivrw  : TCmd = (Code:($DE, $3E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fidivrd  : TCmd = (Code:($DA, $3E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstsw  : TCmd = (Code:($9B, $DD, $3E, $0); Len:3+NearAddr; Flag: Absol);
  fldcw  : TCmd = (Code:($D9, $2E, $0, $0); Len:2+NearAddr; Flag: Absol);
  fstcw  : TCmd = (Code:($9B, $D9, $3E, $0); Len:3+NearAddr; Flag: Absol);
  fstenv  : TCmd = (Code:($9B, $D9, $36, $0); Len:3+NearAddr; Flag: Absol);
  fldenv  : TCmd = (Code:($D9, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
  fsavet  : TCmd = (Code:($9B, $DD, $36, $0); Len:3+NearAddr; Flag: Absol);
  frstort  : TCmd = (Code:($DD, $26, $0, $0); Len:2+NearAddr; Flag: Absol);
{
  : TCmd = (Code:($, $, $, $); Len:; Flag: );
}
  varAddr : Pointer = NIL;
  Relat : Integer = 0;{Относительный адрес}
  ipSave : Integer = 0;
  Sx : Extended = 20.0;
  Sy : Extended = 20.0;
  Cond : Byte = 0;
  InsertFWait : Boolean = True;
  CompileError : Boolean = False;
const
_add_ = $00;
_sub_ = $01;
_mul_ = $02;
_div_ = $03;
_inv_ratio_ = $10;
_sqr_ = $11;
_sqrt_ = $12;
_cube_ = $13;
_cubert_ = $14;
_sin_ = $20;
_cos_ = $21;
_tan_ = $22;
_cotan_ = $23;
_asin_ = $30;
_acos_ = $31;
_atan_ = $32;
_acotan_ = $33;
_exp_ = $40;
_10degx_ = $41;
_2degx_ = $42;
_xdegy_ = $43;{ydegx}
_ln_ = $48;
_log10_ = $49;
_log2_ = $4A;
_logy_ = $4B;{logx}
_xchg_ = $50;
_sign_{x} = $51;
_abs_{x} = $52;
_0_ = $60;
_1_ = $61;
_e_ = $62;
_pi_ = $63;
_load_ = $FF;
_store_ = $FE;

type
  PByte = ^Byte;
  PWord = ^Integer;
  PLong = ^Longint;
var
  Opnd : array[0..255] of Extended;
  RPL : array[0..511] of Byte;
  P : Pointer;
  MCByte : PByte absolute P;
  MCWord : PWord absolute P;
  MCLong : PLong absolute P;
  D, R, e : Integer;
  i : Integer;
  x, y, z : Extended;
  dx : Extended;

  va : Address absolute varAddr;

  CurOfs : Integer absolute P;
  SvOfs : Integer;
  ip : Integer; {instruction pointer} {0..MaxProcSize}

Procedure EGAVGA; External;
Procedure MainCalculator; Assembler;
asm
   ret
{1}dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   {1 строка = 64 байта}
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   {^ 1024 байта}
{2}dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   {1 строка = 64 байта}
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   dd  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   {^ 1024 байта}
{[=========4096 байт===============]}
end;
Procedure BuildScreen;
var
   i, j : Byte;
begin
  SetBkColor(Black);
  ClearViewPort;
  SetColor(DarkGray);
  MoveTo(0, 240);
  LineTo(640, 240);
  LineTo(630, 238);
  LineTo(630, 242);
  LineTo(640, 240);
  MoveTo(320, 480);
  LineTo(320, 0);
  LineTo(318, 10);
  LineTo(322, 10);
  LineTo(320,0);
  SetColor(LightGray);
  for i := 1 to 32 do Line(i*20, 239, i*20, 241);
  for i := 1 to 24 do Line(319, i*20, 321, i*20);
  SetColor(Brown);
  OutTextXY(324, 230, '0');
  OutTextXY(632, 230, 'x');
  OutTextXY(324, 3, 'y');
end;
Procedure SetCmd(Prefix : Byte; cmd : TCmd; Rg : Byte);
{ ip - Смещение инструкции от начала процедуры
  CurOfs - текущее смещение от начала сегмента на позицию ip в процедуре;
  SvOfs - хранит смещение начала процедуры от начала сегмента}
{Т.О. CurOfs=SvOfs+ip}
{varAddr - адрес переменной в памяти, используемый в коде инструкции}
{va.Seg:va.Ofs - адрес, содержащийся в varAddr}
{TCmd : (Code[],len,flag)}
var
  i : Word;
  L : ShortInt;
begin
  if ip < MaxProcSize then
  begin
   if Prefix<>NoPfx then
   begin
     MCByte^ := Prefix;
     inc(ip);
     inc(CurOfs);
   end
  end
    else CompileError := True;
  L := cmd.Len and $0F;
  dec(L);
  if L>=0 then
  if ip < MaxProcSize then
  begin
    for i := 0 to L do
     begin
      MCByte^ := cmd.Code[i];
      inc(CurOfs);
      inc(ip);
     end;
    if (cmd.Flag and Regs) <> 0 then
    begin
      dec(CurOfs);
      MCByte^ := MCByte^ or Rg;
      inc(CurOfs);
    end;
    if (cmd.Flag and Conds) <> 0 then
    begin
      dec(CurOfs);
      MCByte^ := MCByte^ or Cond;
      inc(CurOfs);
    end;
    if (cmd.Flag and Absol) <> 0 then
    begin
      if (cmd.Len and NearAddr)<>0 then
      begin
       MCWord^:=va.Ofs;
       inc(ip, 2);
       inc(CurOfs, 2);
      end;
    end;
    if cmd.Flag and Relative <> 0 then
    begin
      if (cmd.Len and NearAddr)<>0 then
      begin
       MCWord^:=Relat;
       inc(ip, 2);
       inc(CurOfs, 2);
      end;
      if (cmd.Len and ShortAddr)<>0 then;
      begin
       MCByte^:=Lo(Relat);
       inc(ip);
       inc(CurOfs);
      end;
    end;
  end
    else CompileError := True;
end;
Procedure CompileString(S : String);
begin
  ip := 0;
  CurOfs := SvOfs;
  CompileError := False;
  varAddr := @x;
  SetCmd(NoPfx, fldt, noReg);
  SetCmd(fwait, nilcmd, noReg);
  SetCmd(NoPfx, fsin, noReg);
  SetCmd(fwait, nilcmd, noReg);
  varAddr := @y;
  SetCmd(NoPfx, fstpt, noReg);
  SetCmd(retNear, nilcmd, noReg);
end;
Procedure sin; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0FEh   {fsin}
   db      9Bh   {fwait}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure cos; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0FFh   {fcos}
   db      9Bh   {fwait}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure atan; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0E8h {fld1}
   db      9Bh   {fwait}
   db      0D9h, 0F3h {fpatan}
   db      9Bh   {fwait}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure tan; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0F2h {fptan}
   db      9Bh   {fwait}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure cotan; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0FBh{fsincos}
   db      9Bh   {fwait}
   db      0DEh, 0F1h {fdivrp ...}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure InvR; Assembler; {InverseRatio; Inverse Proportion}
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0E8h {fld1}
   db      0DEh, 0F1h {fdivrp ...}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure Sqrt; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0FAh {fsqrt}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure Sqr; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D8h, 0C8h {fmul        st(0),st(0)}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure Abs; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0E1h  {fabs}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;
Procedure Sign; Assembler;
asm
   db      0DBh, 02Eh {fld}
   dw      offset x   {x}
   db      9Bh   {fwait}
   db      0D9h, 0C0h  {fld         st(0)}
   db      0D9h, 0E1h  {fabs}
   db      0DEh, 0F1h {fdivrp ...}
   db      0DBh, 03Eh {fstp}
   dw      offset y   {y}
end;

{   db      000h, 000h {}
{
09Bh, 0DBh, 0E3h finit
DCF9                         fdiv        st(1),st(0)
DEF9                         fdivp       st(1),st(0)
DCF1                         fdivr       st(1),st(0)
DEF1                         fdivrp      st(1),st(0)
}
Procedure FFinit;
Inline($9B/$DB/$E3);
begin
  P := @EGAVGA;
  D := Detect;
  if RegisterBGIdriver(P) < 0 then
  begin
    Writeln('Ошибка регистрации драйвера: ',
    GraphErrorMsg(GraphResult));
    Halt(1);
  end;
  InitGraph(D, R, '');
  e := GraphResult;
  if e <> grOk then
  begin
    WriteLn('Произошла ошибка графики!!!');
    WriteLn(GraphErrorMsg(e));
  end;
  P := @MainCalculator;
  SvOfs := CurOfs;
  BuildScreen;
  ReadKey;
  CompileString('');
  if CompileError then
  begin
   CloseGraph;
   WriteLn('Ошибка компиляции!');
   Halt;
  end;
  FFinit;
  dx := 0.001;
  x := -32.0;
  While x<32.0 do
  begin
    PutPixel(320+Round(Sx*x), 245, Red);
    MainCalculator;
    PutPixel(320+Round(Sx*x), 240-Round(Sy*y), Yellow);
    x := x + dx;
  end;
  ReadKey;
  While KeyPressed do ReadKey;
  CloseGraph;
end.

{Procedure (x : Extended) : Extended; Assembler;
asm
end;}

0D9h, 0C0h
{fld         st(0)}

0D9h, 0C7h
{fld         st(7)}

0D9h, 006h, 085h, 02h
{fld         d,[0285]}

0DDh, 06h, 089h, 02h
{fld         q,[0289]}

0DBh, 02Eh, 091h, 02h
{fld         t,[0291]}

0DFh, 06h, 083h, 02h
{fild        w,[0283]}

0DBh, 06h, 085h, 02h
{fild        d,[0285]}

0DFh, 02Eh, 089h, 02h
{fild        q,[0289]}

0DFh, 026h, 091h, 02h
{fbld        t,[0291]}

0D9h, 016h, 085h, 02h
{fst         d,[0285]}

0DDh, 016h, 089h, 02h
{fst         q,[0289]}

0D9h, 01Eh, 085h, 02h
{fstp        d,[0285]}

0DDh, 01Eh, 089h, 02h
{fstp        q,[0289]}

0DBh, 03Eh, 091h, 02h
{fstp        t,[0291]}

0DFh, 036h, 091h, 02h
{fbstp       t,[0291]}

0D9h, 0EEh
{fldz}

0D9h, 0E8h
{fld1}

0D9h, 0EBh
{fldpi}

0D9h, 0E9h
{fldl2t}

0D9h, 0EAh
{fldl2e}

0D9h, 0ECh
{fldlg2}

0D9h, 0EDh
{fldln2}

0D9h, 0C8h
{fxch        st(0)}

0D9h, 0C9h
{fxch        st(1)}

0D9h, 0CFh
{fxch        st(7)}

0D8h, 0D0h
{fcom        st(0)}

0D8h, 0D7h
{fcom        st(7)}

0D8h, 016h, 085h, 02h
{fcom        d,[0285]}

0DCh, 016h, 089h, 02h
{fcom        q,[0289]}

0D8h, 0D8h
{fcomp       st(0)}

0D8h, 0DFh
{fcomp       st(7)}

0D8h, 01Eh, 085h, 02h
{fcomp       d,[0285]}

0DCh, 01Eh, 089h, 02h
{fcomp       q,[0289]}

0DEh, 0D9h
{fcompp}

0DEh, 016h, 083h, 02h
{ficom       w,[0283]}

0DAh, 016h, 085h, 02h
{ficom       d,[0285]}

0DEh, 01Eh, 083h, 02h
{ficomp      w,[0283]}

0DAh, 01Eh, 085h, 02h
{ficomp      d,[0285]}

0D9h, 0E4h
{ftst}

0DDh, 0E0h
{fucom       st(0)}

0DDh, 0E7h
{fucom       st(7)}

0DDh, 0E8h
{fucomp      st(0)}

0DDh, 0EFh
{fucomp      st(7)}

0DAh, 0E9h
{fucompp}

0D9h, 0E5h
{fxam}

0D8h, 06h, 085h, 02h
{fadd        d,[0285]}

0DCh, 06h, 089h, 02h
{fadd        q,[0289]}
        0
0D8h, 0C1h
{fadd        st(0),st(1)}
        0
0DCh, 0C1h
{fadd        st(1),st(0)}

0D8h, 0C7h
{fadd        st(0),st(7)}

0DCh, 0C7h
{fadd        st(7),st(0)}

0DEh, 0C1h
{faddp       st(1),st(0)}

0DEh, 0C7h
{faddp       st(7),st(0)}

0DEh, 06h, 083h, 02h
{fiadd       w,[0283]}

0DAh, 06h, 085h, 02h
{fiadd       d,[0285]}

0D8h, 026h, 085h, 02h
{fsub        d,[0285]}

0DCh, 026h, 089h, 02h
{fsub        q,[0289]}

0D8h, 02Eh, 085h, 02h
{fsubr       d,[0285]}

0DCh, 02Eh, 089h, 02h
{fsubr       q,[0289]}
        0
0D8h, 0E1h
{fsub        st(0),st(1)}
        8
0DCh, 0E9h
{fsub        st(1),st(0)}

0D8h, 0E9h
{fsubr       st(0),st(1)}

0DCh, 0E1h
{fsubr       st(1),st(0)}

0DEh, 0E9h
{fsubp       st(1),st(0)}

0DEh, 0E1h
{fsubrp      st(1),st(0)}

0DEh, 026h, 083h, 02h
{fisub       w,[0283]}

0DAh, 026h, 085h, 02h
{fisub       d,[0285]}

0DEh, 02Eh, 083h, 02h
{fisubr      w,[0283]}

0DAh, 02Eh, 085h, 02h
{fisubr      d,[0285]}

0D8h, 0C8h
{fmul        st(0),st(0)}

0DCh, 0C9h
{fmul        st(1),st(0)}

0DCh, 0CFh
{fmul        st(7),st(0)}

0DEh, 0C8h
{fmulp       st(0),st(0)}

0DEh, 0C9h
{fmulp       st(1),st(0)}

0DEh, 0CFh
{fmulp       st(7),st(0)}

0D8h, 0Eh, 085h, 02h
{fmul        d,[0285]}

0DCh, 0Eh, 089h, 02h
{fmul        q,[0289]}

0DEh, 0Eh, 083h, 02h
{fimul       w,[0283]}

0DAh, 0Eh, 085h, 02h
{fimul       d,[0285]}

0D8h, 0F0h
{fdiv        st(0),st(0)}

0DCh, 0F9h
{fdiv        st(1),st(0)}

0DCh, 0FFh
{fdiv        st(7),st(0)}

0DEh, 0F8h
{fdivp       st(0),st(0)}

0DEh, 0F9h
{fdivp       st(1),st(0)}

0DEh, 0FFh
{fdivp       st(7),st(0)}

0D8h, 036h, 085h, 02h
{fdiv        d,[0285]}

0DCh, 036h, 089h, 02h
{fdiv        q,[0289]}

0DEh, 036h, 083h, 02h
{fidiv       w,[0283]}

0DAh, 036h, 085h, 02h
{fidiv       d,[0285]}

0D8h, 0F8h
{fdivr       st(0),st(0)}

0DCh, 0F1h
{fdivr       st(1),st(0)}

0DCh, 0F7h
{fdivr       st(7),st(0)}

0DEh, 0F0h
{fdivrp      st(0),st(0)}

0DEh, 0F1h
{fdivrp      st(1),st(0)}

0DEh, 0F7h
{fdivrp      st(7),st(0)}

0D8h, 03Eh, 085h, 02h
{fdivr       d,[0285]}

0DCh, 03Eh, 089h, 02h
{fdivr       q,[0289]}

0DEh, 03Eh, 083h, 02h
{fidivr      w,[0283]}

0DAh, 03Eh, 085h, 02h
{fidivr      d,[0285]}

0D9h, 0FAh
{fsqrt}

0D9h, 0FDh
{fscale}

0D9h, 0F4h
{fxtract}

0D9h, 0F8h
{fprem}

0D9h, 0F5h
{fprem1}

0D9h, 0FCh
{frndint}

0D9h, 0E1h
{fabs}

0D9h, 0E0h
{fchs}

0D9h, 0FFh
{fcos}

0D9h, 0FEh
{fsin}

0D9h, 0FBh
{fsincos}

0D9h, 0F2h
{fptan}

0D9h, 0F3h
{fpatan}

0D9h, 0F0h
{f2xm1}

0D9h, 0F1h
{fyl2x}

0D9h, 0F9h
{fyl2xp1}

09Bh, 0DBh, 0E3h
{finit}

09Bh, 0DFh, 0E0h
{fstsw       ax}

09Bh, 0DDh, 03Eh, 083h, 02h
{fstsw       [0283]}

0D9h, 02Eh, 083h, 02h
{fldcw       [0283]}

09Bh, 0D9h, 03Eh, 083h, 02h
{fstcw       [0283]}

09Bh, 0DBh, 0E2h
{fclex}

09Bh, 0D9h, 036h, 083h, 02h
{fstenv      [0283]}

0D9h, 026h, 083h, 02h
{fldenv      [0283]}

09Bh, 0DDh, 036h, 083h, 02h
{fsave       t,[0283]}

0DDh, 026h, 083h, 02h
{frstor      t,[0283]}
[]
0D9h, 0F7h
{fincstp}

0D9h, 0F6h
{fdecstp}

0DDh, 0C0h
{ffree       st(0)}

0DDh, 0C7h
{ffree       st(7)}

0D9h, 0D0h
{fnop}

09Bh
{fwait}

Назад