--
Jason Meltz
10770...@compuserve.com
TurboPascal programmer & Tom Clancy fan
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.
: --
: Jason Meltz
: 10770...@compuserve.com
: 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
email:won...@cs.cuhk.edu.hk
On 1997-03-27 sai...@ALife.Lab(SuperSaiyan) said:
>: 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
>: 10770...@compuserve.com
>: 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
john...@iamerica.net
AAAAA - American Assoc. Against Acronym Abuse
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.
> IRET tells you that your Returning from an Interrupt, where as
IRET pops the IP, the CS, and the flags
> RETF tells you your returning from a FAR call, and RET
RETF pops the IP and CS
--
>---R.J. Dunnill, Squirrel Systems Engineering Services Group
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
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.
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
--
<---->