Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!samsung!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!fuug!tuura!risto From: risto@tuura.UUCP (Risto Lankinen) Newsgroups: comp.os.msdos.programmer Subject: Re: Writing assembly procedures for higher level languages Message-ID: <974@tuura.UUCP> Date: 29 Jan 91 11:49:36 GMT References: <1991Jan24.133054.8715@wpi.WPI.EDU> <1991Jan24.221332.5802@bradley.bradley.edu> Organization: Nokia Data Systems Oy Lines: 44 data@buhub (Mark Hall) writes: >jhall@wpi.WPI.EDU (John Clinton Hall) writes: >>AccordingtMicrosoft's _Mixed-Language Programming Guide_, "A procedure >>caled from any of the Microsoft high-level languages should preserve the >>values of SI, DI, SS, and DS (in additon to BP, which is already saved)." >>However, does one need to save the ES register if it is mdified? How abo >>the flags register? >To save the ES register, you can always: > MOV AX,ES > PUSH AX Hi! Why not PUSH ES directly? Anyway, I've had bad experience with saving the ES register in programming in MASM for Windows. I once thought it was a good idea to... PUSH DS MOV DS,AX ; This is part of the standard Windows call sequence PUSH SI PUSH ES PUSH DI ; This order of PUSH:es facilitates LES and LDS at restore-time Now, severe errors bugged me (literally) quite a while - until I discovered, that in protected-mode environment the actual segment, whose selector ES were, has a chance of being invalidated during subsequent calls to Windows' kernel. The errors were the result of the LES instruction (or POP ES for that matter) at the end of the function loading the (at that time) invalid selector 'back' to a segment register. This is not a problem with the pushed DS , because there is a mechanism which keeps the saved DS (and the CS of the far return) automatically up-to-date. Terveisin: Risto Lankinen -- Risto Lankinen / product specialist *************************************** Nokia Data Systems, Technology Dept * 2 2 * THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME! Now working on 2 +1 * replies: risto@yj.data.nokia.fi ***************************************