program ExtMem;
  {-Display the amount of extended memory in kilobytes}
uses Dos;

  function GetListOfLists : Pointer;
    {-Get pointer to the DOS List of Lists}
  var
    Regs : Registers;
  begin
    with Regs do begin
      AH := $52;
      MsDos(Regs);
      GetListOfLists := Ptr(ES, BX);
    end;
  end;


  function ExtMemInK : Word;
    {-Return the amount of extended memory}
  var
    P : Pointer;
  begin
    P := GetListOfLists;
    Inc(Word(P), $45);    {extended mem in K at offset 45h}
    ExtMemInK := Word(P^);
  end;

begin
  if Swap(DosVersion) < $0400 then begin
    WriteLn('Requires DOS 4 or greater');
    Halt;
  end;
  WriteLn(ExtMemInK, 'K extended memory');
end.
