🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5326

Re: iret and retf

#5326
From: Fridrik Skulason
Date: Wed, 20 Mar 1991 13:23
55 lines
2237 bytes
In article <1991Mar14.031024.12576@msuinfo.cl.msu.edu> leeda@frith.egr.msu.edu (Dae Hee Lee) writes:
>
>When can I use retf instead of iret?

A - When returning from an interrupt routine:

Normally one uses IRET when returning from an interrupt call.  IRET will pop
the return address and the flags (total of 6 bytes) from the stack.

RETF by itself will only pop the return address from the stack, and will
leave the original flags.  This can be used at the end of an interrupt
routine, if you want to return some information in the flag register.

The INT 25H and INT 26H routines do this for example.

Another possibility is to use RETF 2, which will discard the original flags.

B - When arguments need to be removed from the stack

In languages like C and Pascal, arguments are generally passed on the stack.
In some cases the caller is supposed to clear the stack afterwards, but in
other cases the called program should do this.  


Possibility 1)
                 PUSH  ARG1
                 PUSH  ARG2
                 CALL  SUBPROGRAM
                 ADD   SP,4       ; the calling program clears the stack
                 :
                 :
SUBPROGRAM:      :
                 :
                 RETF


Possibility 2)

                 PUSH  ARG1
                 PUSH  ARG2
                 CALL  SUBPROGRAM
                 :
                 :
SUBPROGRAM:      :
                 :
                 RETF 4   ; the called program clears the stack

The methods are equally good, however.

-frisk

--
Fridrik Skulason      University of Iceland  |       
Technical Editor of the Virus Bulletin (UK)  |  Reserved for future expansion
E-Mail: frisk@rhi.hi.is    Fax: 354-1-28801  |   
Technical Details
Message-ID: <2945@krafla.rhi.hi.is>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!isgate!krafla!frisk
References: <1991Mar14.031024.12576@msuinfo.cl.msu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!isgate!krafla!frisk
From: frisk@rhi.hi.is (Fridrik Skulason)
Newsgroups: comp.os.msdos.programmer
Subject: Re: iret and retf
Message-ID: <2945@krafla.rhi.hi.is>
Date: 20 Mar 91 13:23:22 GMT
References: <1991Mar14.031024.12576@msuinfo.cl.msu.edu>
Reply-To: frisk@rhi.hi.is (Fridrik Skulason)
Organization: University of Iceland (RHI)
Lines: 55