[comp.lang.pascal] INT 25h problem

C0361@univscvm.csd.scarolina.edu ( Thomas Jenkins) (02/06/91)

Hi,

  Seems to me the problem is best handled with Inline, linked in assembly or
the ASM block in TP 6.0 .  Since the flags are left on the stack after the
call, using Intr will never work.  TP sets up code like:  ( very simplified )

....
push registers    (*  before Intr call  *)
set registers to you register variable
Int 25h
pop registers     (* after call         *)

and then you issue:

ASM
  POPF
END ;

TP is in effect poping the flags into one of the registers and then you are
poping what was a register into the flags.  Why does this make it bomb?
Because the code segment and data segment are now invalid - IE, you're running
wild!

If you have TP 6.0, use the ASM block for pushing the registers, the flags,
setting up the registers for the call and returning the CPU to it's pre-
interupt status.  Then examin you data.

If you have some other TP version, Use an assembler to write a Proc to do this
and link it in.  Otherwise ( and this isn't much harder than assembly ) use
inline statements to do the job.

tom

THOMAS E. JENKINS, JR.                +--------+  FROM SHOE  +--------+
                                      |"IS THE COMPUTER STILL GIVING  |
PROGRAMMER,                           | YOU TROUBLE?..."              |
  UNIVERSITY OF SOUTH CAROLINA        |"NO, NOT ANYMORE..."           |
  C0361 AT UNIVSCVM.BITNET            |"WHAT DID YOU DO?..."          |
  C0361 AT UNIVSCVM.CSD.SCAROLINA.EDU |" I TURNED IT OFF."            |
                                      +-------------------------------+

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (02/07/91)

In article <25848@adm.brl.mil> C0361@univscvm.csd.scarolina.edu ( Thomas Jenkins) writes:
>Hi,
>
>  Seems to me the problem is best handled with Inline, linked in assembly or
>the ASM block in TP 6.0 .  Since the flags are left on the stack after the
>call, using Intr will never work. 

  The following is from _Turbo_Pascal_Advanced_Techniques_, by Chris Olsen
  and Gary Stoker, from the Que Programming Series, and is reproduced here
  without permission from the authors.

  *************************
  Procedure AbsRead(var buf; drive,number,logical : word);
  var 
    result : integer;
  begin
    inline(
      $55/		{ Push BP }
      $1E/		{ Push DS }
      $33/$C0/		{ Xor AX,AX }
      $89/$86/Result/	{ Mov Result,AX }
      $8A/$86/Drive/	{ Mov AL, Drive }
      $8B/$8E/Number/	{ Mov CX, Number }
      $8B/$96/Logical/	{ Mov DX, Logical }
      $C5/$9E/Buf/	{ Lds BX,Buf }
      $CD/$25/		{ Int $25 }
      $5B/		{ Pop BX }
      $1F/		{ Pos DS }
      $5D/		{ Pop BP }
      $73/$04/		{ Jnb Done }
      $89/$86/Result);	{ Mov Result,AX }
  end;

  Procedure AbsWrite(var buf; drive,number,logical : word);
  var 
    result : word;
  begin
    inline(
      $55/		{ Push BP }
      $1E/		{ Push DS }
      $33/$C0/		{ Xor AX,AX }
      $89/$86/Result/	{ Mov Result,AX }
      $8A/$86/Drive/	{ Mov AL,Drive }
      $8B/$8E/Number/	{ Mov CX,Number }
      $8B/$96/Logical/	{ Mov DX,Logical }
      $C5/$9E/Buf/	{ Lds BX,Buf }
      $CD/$26/		{ Int $26 }
      $5B/		{ Pop BX }
      $1F/		{ Pop DX }
      $5D/		{ Pop BP }
      $73/$04/		{ Jnb Done }
      $89/$86/Result);  { Mov Result,AX if error }
  end;
  ************************

  Bob Beauchaine
  bobb@vice.ICO.TEK.COM