News:

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

Stack Frame

Started by caraveiro, February 18, 2009, 11:59:48 PM

Previous topic - Next topic

caraveiro

What does [4*4] is used for in the code below?




OPTION PROLOGUE:NONE            ; turn off the stack frame
OPTION EPILOGUE:NONE
align 8
Base64Encode              proc pInputData:DWORD,dwDataLen:DWORD,pOutputStr:DWORD
        ;     
    push ebp
    push esi
                    push edi
                    push ebx
                    mov esi,[esp+1*4][4*4]     ;pInputData
                    mov ebp,[esp+2*4][4*4]   ;dwDataLen
                    mov edi,[esp+3*4][4*4]     ;pOutputStr



Downloaded from http://www.geocities.com/asmsoft3264/src.html


Also has this line:

sub eax,[esp+3*4][1*4]    ;pOutputStr

Dunno what's [1*4] is for!!!


"knowledge is now free at last, everything should be free from now on, enjoy knowledge and life and work for everybody else"
+ORC
http://www.fravia.com

drizz

I wrote it, so I think I can explain it  :green2

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

this turns off automatic stack frame generation by masm

push ebp
push esi
push edi
push ebx

I preserve all non-volatile registers by stdcall convention, this makes esp decrease by 4*4 bytes

mov esi,[esp+1*4][4*4];pInputData
mov ebp,[esp+2*4][4*4];dwDataLen

I access first dword argument (1*4) and second (2*4)  through esp and I also account for the "4*4" change


pop ebx
mov [eax],bp
pop edi
pop esi
sub eax,[esp+3*4][1*4];pOutputStr
pop ebp
ret 3*4

at the end esp is increased by 3*4 bytes because of the three "pop reg" instructions
hence, by accessing third argument (3*4) I only add 1*4 bytes.

finally function returns with 3*4 bytes popped by stdcall convention.

HTH
The truth cannot be learned ... it can only be recognized.

caraveiro

Wow!

Trying to understand the code, I'd been reading this:

http://www.asmcommunity.net/board/index.php?action=printpage;topic=29275.0

and:

http://blogs.msdn.com/larryosterman/archive/2007/03/12/fpo.aspx

But your explanation, drizz, was terrific!    :U

.
.
.

I'd been playing:


mov esi,[esp+1*4][2*4][1*4][1*4];pInputData


That's cool!





"knowledge is now free at last, everything should be free from now on, enjoy knowledge and life and work for everybody else"
+ORC
http://www.fravia.com