Use of RETF in a TSRs ISR 
Author Message
 Use of RETF in a TSRs ISR

I would appreciate hearing from anyone with suggestions or
information on the use of the assembly instruction RETF in
interrupts. Specifically, TSR program ISR-replacement routines.

--
                           Jason Meltz

               TurboPascal programmer & Tom Clancy fan



Sun, 12 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

Quote:

> I would appreciate hearing from anyone with suggestions or
> information on the use of the assembly instruction RETF in
> interrupts. Specifically, TSR program ISR-replacement routines.

Generally, interrupts are expected to preserve flags... they
are restored by IRET, but not by RETF, so the last may cause
problems. Except when flag changing is allowed.


Sun, 12 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

: I would appreciate hearing from anyone with suggestions or
: information on the use of the assembly instruction RETF in
: interrupts. Specifically, TSR program ISR-replacement routines.

: --
:                          Jason Meltz

:                TurboPascal programmer & Tom Clancy fan

        Even if changing of flags is what you desire, clearing of
        the flag in stack is your duty. retf would not do anything
        for you in clearing this word pushed when interrupt occurs.
        Basically, retf is not normally used unless you concern much
        about the programming style, since any far procedure (an ISR
        MUST be a FAR procedure) will have the ret instruction changed
        to retf by the assembler.

--
Terence



Mon, 13 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR


   >: I would appreciate hearing from anyone with suggestions or
   >: information on the use of the assembly instruction RETF in
   >: interrupts. Specifically, TSR program ISR-replacement routines.
   >: --
   >:       Jason Meltz

   >:                TurboPascal programmer & Tom Clancy fan
   >Even if changing of flags is what you desire, clearing of
   >the flag in stack is your duty. retf would not do anything
   >for you in clearing this word pushed when interrupt occurs.
   >Basically, retf is not normally used unless you concern much
   >about the programming style, since any far procedure (an ISR
   >MUST be a FAR procedure) will have the ret instruction changed
   >to retf by the assembler.
     That's one thing I like about A86/A386 -> If you want a RETF,
     just code it as RETF, don't put RET and trust that the compiler
     is going to change it for you.  When you get in the habbit of
     letting the compiler do everything for you, you tend to forget
     certain things, and even though the top of the procedure has
     the word, there's too many people like myself who'll look
     at the bottom of a really long procedure when we're editing
     something at the very bottom, say 'RET', yeah that's near...
     But if your doing an interrupt service routine, for readibility,
     why not use IRET? I just did a quick check of Debug and

     RET  = 0C3h
     RETF = 0CBh
     IRET = 0CFh

     (For the longest time I thought they did do the exact same thing,
      but apparently there's a slight difference..., and for readibility,
      IRET tells you that your Returning from an Interrupt, where as
      RETF tells you your returning from a FAR call, and RET
      tells you that (most people) your returning from a near call,
      (TASM/MASM fans) tells them your returning from somewhere....

John H. Guillory

AAAAA - American Assoc. Against Acronym Abuse



Thu, 16 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

Quote:
>     RET  = 0C3h
>     RETF = 0CBh
>     IRET = 0CFh

>     (For the longest time I thought they did do the exact same thing,
>      but apparently there's a slight difference..., and for readibility,
>      IRET tells you that your Returning from an Interrupt, where as
>      RETF tells you your returning from a FAR call, and RET
>      tells you that (most people) your returning from a near call,
>      (TASM/MASM fans) tells them your returning from somewhere....

RET only pops the IP, and is a near return. RETF pops the IP and CS, and is a
far return. IRET pops the IP, CS, and flags. When an interrupt occurs, the flags
are pushed in addition to the program counter and segment. For routines having
arguments, RET and RETF can specify additional stack pointer increments. So, one
pops one word, one pops two words, and one pops three words.

--
http://cust.iamerica.net/mcdivitt/



Thu, 16 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

Quote:

>       IRET tells you that your Returning from an Interrupt, where as

IRET pops the IP, the CS, and the flags

Quote:
>       RETF tells you your returning from a FAR call, and RET

RETF pops the IP and CS

--

Quote:
>---R.J. Dunnill, Squirrel Systems Engineering Services Group



Thu, 16 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

Quote:
> I would appreciate hearing from anyone with suggestions or
> information on the use of the assembly instruction RETF in
> interrupts. Specifically, TSR program ISR-replacement routines.

You shouldn't be using RETF in an interrupt.  It will leave the flags on
the stack.  (that's very bad)  Either: use IRET (will restore the flags
that were set on call) or RETF 2 (use the flags that you set before
returning).  The RETF 2 is used to allow setting the carry, for example,
prior to returning the caller.
eg.  STC        ;specify error occurred
     RETF 2


Mon, 20 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

Quote:

> I would appreciate hearing from anyone with suggestions or
> information on the use of the assembly instruction RETF in
> interrupts. Specifically, TSR program ISR-replacement routines.

IRET is used to terminate a ISR by restoring CS:IP and the flags.
RETF only restores CS:IP. Using a basic RETF in an ISR destroys
the stack structure (and leave the flag-register in an unknown
state). At least a RETF 2 (availible on x186 and above)
instruction is needed.

Complete replacement of IRET by RETF would be:
  push word ptr sp+4 (or bp+6 if you set up an stack frame)
  popf
  retf 2

This is useful if you want to change the flags of the interupted
instruction. I.e. to emulate different behavior of traped
instructions (FP/bound/...).

  mov  ax,word ptr sp+4
(... manipulate flags ...)
  push ax
  popf
  retf 2

But the same result can be archieved if just by manipulating the
(flag-)word at sp+4 (bp+6) and using a regular IRET.

Gruss
Hans

P.S.: please don't post x86 related questions to comp.lang.asm370.
      Especialy since the /370 has a stackless structure.
--
Ich denke, also bin ich, also gut.
HRK.



Mon, 20 Sep 1999 03:00:00 GMT  
 Use of RETF in a TSRs ISR

:      That's one thing I like about A86/A386 -> If you want a RETF,
:      just code it as RETF, don't put RET and trust that the compiler
:      is going to change it for you.  When you get in the habbit of
:      letting the compiler do everything for you, you tend to forget
:      certain things, and even though the top of the procedure has
:      the word, there's too many people like myself who'll look
:      at the bottom of a really long procedure when we're editing
:      something at the very bottom, say 'RET', yeah that's near...
:      But if your doing an interrupt service routine, for readibility,
:      why not use IRET? I just did a quick check of Debug and

  I agree.  I use...

RET_F   MACRO
        DB 0CBH
        ENDM

RET_N   MACRO
        DB 0C3H
        ENDM

RET_FP  MACRO X
        DB 0CAH
        DW X
        ENDM

RET_NP  MACRO X
        DB 0C2H
        DW X
        ENDM

--
<---->



Wed, 22 Sep 1999 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Use of RETF in a TSRs ISR

2. Use of RETF in a TSRs ISR

3. *** ISR trouble using Watcom c

4. Wanted Code on ISR using PIC2 Interrupts

5. WinXP kernel mode : using FPU in isr

6. retf

7. retf

8. retf question

9. RETF

10. RETF x IRET

11. TSRs in VM

12. TSRs in VM

 

 
Powered by phpBB® Forum Software