Functions without prologue/epilogue code

Started by Vortex, February 26, 2006, 01:29:49 PM

Previous topic - Next topic

Vortex

Hi Hutch,

Concerning the POASM test bed, I think there is a small bug with your szCopy code translated to POASM. The szCopy function should be typed as szCopy@8 Your original code declares this function as szCopy which has no any decoration.

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

      .model flat, stdcall      ; memory model & calling convention
      option casemap :none      ; case sensitive

      EXTERNDEF szCopy@8 :DWORD

    .code

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

align 4

comment * -----------------------------------------------
        copied length minus terminator is returned in EAX
        ----------------------------------------------- *
align 16

szCopy@8:     ; proc src:DWORD,dst:DWORD

    push ebp

    mov edx, [esp+8]
    mov ebp, [esp+12]
    xor ecx, ecx        ; ensure no previous content in ECX
    mov eax, -1

  @@:
    add eax, 1
    mov cl, [edx+eax]
    mov [ebp+eax], cl
    test cl, cl
    jnz @B

    pop ebp

    ret 8

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

end

hutch--

Erol,

It does not need to. The EXTERNDEF is only to make the label visible. It is not a data specifier.


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

      .model flat, stdcall  ; 32 bit memory model
      option casemap :none  ; case sensitive
      option cstrings:on    ; enable C string escapes

    ; *************
    ; include files
    ; *************
      include \poasm\include\windows.inc
      include \poasm\include\plib.inc
      include \poasm\include\gdi32.inc
      include \poasm\include\user32.inc
      include \poasm\include\kernel32.inc
      include \poasm\include\Comctl32.inc
      include \poasm\include\comdlg32.inc
      include \poasm\include\shell32.inc
      include \poasm\include\msvcrt.inc
      include \poasm\macros\macros.asm

    ; *********
    ; libraries
    ; *********
      includelib \poasm\lib\plib.lib
      includelib \poasm\lib\gdi32.lib
      includelib \poasm\lib\user32.lib
      includelib \poasm\lib\kernel32.lib
      includelib \poasm\lib\Comctl32.lib
      includelib \poasm\lib\comdlg32.lib
      includelib \poasm\lib\shell32.lib
      includelib \poasm\lib\msvcrt.lib

    .data
      tst db "This is a test",13,10,0
      buf db 64 dup (0)

    .code

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

    call main
    inkey
    exit

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

main proc

    cls
    invoke szCopy,ADDR tst,ADDR buf
    print ADDR buf
    ret

main endp

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

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Sorry Hutch, my apologies, I didn't knew this feature of EXTERNDEF Thanks for the example.

hutch--

Erol,

It does do something different though in that the no stack frame procedure from the library is written after the lookup table where the rest of the normal stack frame procedures are written before it so it looks like POLINK treats them differently. I think when we have more documentation available for POASM that there may be a tidier way to do it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

WiteG

I'm fresh POASM user but have to say this assembler looks great.
However there is no PROLOGUE/EPILOGUE (at least: PROLOGUE:NONE/EPILOGUE:NONE) option.
As far I saw we can avoid epilogue code using retn/retf in exchange for ret opcode.
So, my question is : can we do anything better than "labeling" procedure like Vortex did:

szCopy@8:     ; proc src:DWORD,dst:DWORD

Is there any chance for PROLOGUE:NONE/EPILOGUE:NONE support in POASM ?

hutch--

Hi WiteG,

Welcome on board. POASM is a very good tool that can do almost everything MASM can do well with the exception of MASMs macros which are still more advanced. It already has a superset of operators that masm does not do, include direct binary data, takes larger .DATA section line legths and a number of other goodies. Used in conjunction with Pelle's linker, library manager and resource compiler, you can build almost anything you like. Pelle's IDE has an excellent resource editor built into it so by downloading Pelle's complete package you get a heap of good stuff.

As far as the MASM notation of PROLOGUE and EPILOGUE macros, you don't need to use them, just write stack frame free procedures directly off the start label like as follows.


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

      .model flat, stdcall      ; memory model & calling convention
      option casemap :none      ; case sensitive

      EXTERNDEF szCopy :DWORD

    .code

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

align 4

comment * -----------------------------------------------
        copied length minus terminator is returned in EAX
        ----------------------------------------------- *
align 16

szCopy:

    push ebp

    mov edx, [esp+8]
    mov ebp, [esp+12]
    xor ecx, ecx        ; ensure no previous content in ECX
    mov eax, -1

  @@:
    add eax, 1
    mov cl, [edx+eax]
    mov [ebp+eax], cl
    test cl, cl
    jnz @B

    pop ebp

    ret 8

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

end
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

WiteG

Ok I have tested it  :bg
Code like:

EXTERNDEF szCopy@8 :PROC
and
szCopy@8:

works well under POASM, MASM and TASM.