News:

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

No stack frame test code.

Started by hutch--, February 19, 2008, 10:22:50 PM

Previous topic - Next topic

hutch--

I have been playing with a very complicated algo that starts with about 20 local variables and runs at about 300 lines. I have so far manually optimised the example but still with a stack frame and while the speed eventually came up to pace it needws to be faster and making EBP available should be able to make that possible.

This is the test piece to manually code an algo that has an external call in it with a set of equates for stack arguments, local arguments and the main stack space allocation.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    nostackframe PROTO :DWORD,:DWORD,:DWORD,:DWORD

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    fn nostackframe,0,"Message","Title",MB_OK

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

    align 16

    hndl equ <DWORD PTR [esp+4+lva]>
    tmsg equ <DWORD PTR [esp+8+lva]>
    tttl equ <DWORD PTR [esp+12+lva]>
    styl equ <DWORD PTR [esp+16+lva]>

    _ebx equ <DWORD PTR [esp+4]>
    _esi equ <DWORD PTR [esp+8]>
    _edi equ <DWORD PTR [esp+12]>
    _ebp equ <DWORD PTR [esp+16]>

    lcl1 equ <DWORD PTR [esp+20]>
    lcl2 equ <DWORD PTR [esp+24]>
    lcl3 equ <DWORD PTR [esp+28]>
    lcl4 equ <DWORD PTR [esp+32]>

nostackframe proc p_hndl:DWORD,p_tmsg:DWORD,p_tttl:DWORD,p_styl:DWORD

    lva equ <36>            ; local variable allocation

    sub esp, lva            ; allocate local variable space on stack

    mov _ebx, ebx           ; store registers on stack
    mov _esi, esi
    mov _edi, edi
    mov _ebp, ebp

    push styl
    push tttl[4]            ; the [number] is a 4 byte stack correction for each push
    push tmsg[8]
    push hndl[12]
    call MessageBoxA

    mov ebx, _ebx           ; load registers from stack
    mov esi, _esi
    mov edi, _edi
    mov ebp, _ebp

    add esp, lva            ; balance stack on exit
    ret 16

nostackframe endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


Its disassembly looks like this.


fn_00401020:

    sub esp, 24h
    mov [esp+4], ebx
    mov [esp+8], esi
    mov [esp+0Ch], edi
    mov [esp+10h], ebp
    push DWORD PTR [esp+34h]
    push DWORD PTR [esp+34h]
    push DWORD PTR [esp+34h]
    push DWORD PTR [esp+34h]
    call MessageBoxA
    mov ebx, [esp+4]
    mov esi, [esp+8]
    mov edi, [esp+0Ch]
    mov ebp, [esp+10h]
    add esp, 24h
    ret 10h
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php