Compute of Pi number

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: KMP (Club of young programmers)

Author: Ľuboš Saloky
Program: Pi.pasPi2.pas
File exe: Pi.exePi2.exe

Compute of Pi number.
{ pi2.pas                                                           }
{ Vypocet cisla Pi. Verzia 2.                                       }
{                                                                   }
{ Author: Ľuboš Saloky                                              }
{ Datum: 01.01.1996                           http://www.trsek.com  }
 
{$G+}
program Vypocet_cisla_pi; {verzia 2.0}
{$M 1024,0,0}
{  moderne cez arkustangensy, nie len tak ledabolo ...
   vzorec: Pi = 48*arctg(1/18)+32*arctg(1/57)-20*arctg(1/239)  }
 
const a:array[1..8] of byte=(0,0,0,0,$12,$34,$56,$78);
      b:array[1..8] of byte=(0,0,0,0,$21,$43,$88,$99);
      Dlzka:word=4;
var ASeg,BSeg:word;
 
{ ----- Scitanie; 2 operandy s mojim formatom ----- }
procedure Plus(Seg1,Seg2:word);assembler;{vysledok v Seg2}
asm
            std
            push ds
            mov ds,ASeg           {DS:SI - 1. cislo}
         {  mov es,BSeg  }        {ES:DI - 2. cislo a vysledok}
            mov si,word ptr Dlzka
            add si,4
            mov di,si             {DI aj SI na poslednu cislicu}
            mov cx,Dlzka
@Dalsia:    lodsb
            add al,byte[es:di]
            daa
            stosb
            loop @Dalsia
            pop ds
end;
{ ----- HLAVNY PROGRAM ----- }
BEGIN
  asm
             mov ah,48h
             mov bx,1
             int 21h              {alokacia ASeg}
             mov ASeg,ax
             mov ah,48h
             mov bx,1
             int 21h              {alokacia BSeg}
             mov BSeg,ax
 
             mov si,offset a
             mov es,ASeg
             xor di,di
             mov cx,4
         rep movsw
             mov si,offset b
             mov es,BSeg
             xor di,di
             mov cx,4
         rep movsw
  end;
  Plus(Seg(a),Seg(b));
{ ----- koniec programu ----- }
  asm
             mov es,ASeg
             mov ah,49h
             int 21h              {dealokacia ASeg}
             mov es,BSeg
             mov ah,49h
             int 21h              {dealokacia BSeg}
  end;
  readln;
END.