How do I translate an assembly function into pascal code?

There is a function written for Delphi, with an assembler insert, you need to translate it into pascal, the lack of deep knowledge of Assembler does not allow you to do this yourself (knowledge of it stopped at Z80 in the 90s). I'm just afraid to make a mistake: according to my understanding, the coprocessor processes real numbers (pushing, comparing, multiplying, finding the sine and conditional transitions through the main processor). The function is part of the construction of smoothed lines.

I beg give comments on the algorithm for executing commands in the function, I hope to translate their meaning into pascal for Lazarus.

function GetB(D,W: Double): byte;  
// Retuns the pixel byte value depending the distance 
// from the line relative to the line width
asm
    fld      W
    fsub     D
    fst      D
    fcomp    N3
    fstsw    ax
    sahf
    jb       @NotBig
    mov      al,$ff
    jmp      @End
  @NotBig:
    fld      D
    fcomp    N0
    fstsw    ax
    sahf
    jnb      @SinV
    xor      eax,eax
    jmp      @End
  @SinV:
    FLD      D
    FLD      N05
    FMUL
    FSIN
    FLD      st(0)
    FMUL
    FLD      N255
    FMUL
    FWAIT
    Push     esp
    FSUB     N04
    FISTP    dword ptr [esp]
    POP      eax
  @End:
end;
Author: Viktor Tomilov, 2018-03-01

1 answers

A somewhat strange assembler code, either tracing paper from another code, or was written a long time ago. I will not give comments - @kot-da-vinci is absolutely right that the assembly language reference is more than enough (for example, I read/write assembly code at least once a week, but I do not remember all the details for all the commands, and it is enough to have several PDFs at hand to remember).

You are missing the definition of a number of variables, I believe they are double.

var
  N3, N0, N255, N04, n05:double;

function _GetB(D,W: Double): byte;
begin
   D:=W-D;
   if D >= N3 then
      begin
        Result:=255;
        Exit;
      end;
   if D < N0 then
     begin
       Result:=0;
       exit
     end;
    Result:=round(N255*sqr(sin(d*n05)) - n04);
end;
 1
Author: Viktor Tomilov, 2018-03-01 14:35:48