News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

The usage of esi,edi,esp

Started by Eric4ever, March 30, 2006, 02:07:50 PM

Previous topic - Next topic

Eric4ever

I'm not very clear about it, is there some tutorials or dissertations to explain it? THX

hutch--

Eric,

Your question is a bit too general but I will have a go at it. ESP is the stack pointer and unless you know exactly what you are doing, its easy to make a mess of code by trying to use ESP incorrectly. You tend to manually code using ESP with procedures that have no stack frame but you really have to know what you are doing with it to ensure the stack is balanced on exit from the procedure.

ESI and EDI need to be preserved in normal procedures as the OS expects this but if you have them preserved already in one proc, as long as you don't interact with any other procedure that expects the same, you don't have to preserve them again but again you must know what you are doing with this style of code.

Generally if you use a normal stack frame, ESP EBP are preserved and with EBX ESI and EDI, they must be preserved if you are going to use those registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

Hi Eric, please look in \masm32\help\ASMINTRO.HLP. It has lots of great tips in there. I found it instrumental! :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Eric4ever

Quote from: hutch-- on March 30, 2006, 02:17:05 PM
Eric,

Your question is a bit too general but I will have a go at it. ESP is the stack pointer and unless you know exactly what you are doing, its easy to make a mess of code by trying to use ESP incorrectly. You tend to manually code using ESP with procedures that have no stack frame but you really have to know what you are doing with it to ensure the stack is balanced on exit from the procedure.

ESI and EDI need to be preserved in normal procedures as the OS expects this but if you have them preserved already in one proc, as long as you don't interact with any other procedure that expects the same, you don't have to preserve them again but again you must know what you are doing with this style of code.

Generally if you use a normal stack frame, ESP EBP are preserved and with EBX ESI and EDI, they must be preserved if you are going to use those registers.
Quote from: Mark Jones on March 30, 2006, 05:54:19 PM
Hi Eric, please look in \masm32\help\ASMINTRO.HLP. It has lots of great tips in there. I found it instrumental! :U

ThX :U
\masm32\help\ASMINTRO.HLP is a good tutorial for sure. :thumbu