The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Eric4ever on March 30, 2006, 02:07:50 PM

Title: The usage of esi,edi,esp
Post by: Eric4ever on March 30, 2006, 02:07:50 PM
I'm not very clear about it, is there some tutorials or dissertations to explain it? THX
Title: Re: The usage of esi,edi,esp
Post by: 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.
Title: Re: The usage of esi,edi,esp
Post by: 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
Title: Re: The usage of esi,edi,esp
Post by: Eric4ever on March 31, 2006, 02:04:18 AM
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