문제

Is there any way to generate the following header and footer for routines in nasm without the need to explicitly code them every time I define a new routine?

Header:

  push  ebp
  mov   ebp, esp    ; Entry code - set up ebp and esp

body of the routine

Footer:

  mov   esp, ebp    ; Function exit code
  pop   ebp
  ret

I'm looking for something like:

some command that generates entry code
body of the routine
some command that generates exit code
도움이 되었습니까?

해결책

You could define a multi-line macro...

%macro  prologue 1 

        push    ebp 
        mov     ebp,esp 
        sub     esp,%1 

%endmacro

Source.

You could define one for function entry and exit.

%macro  prologue 1 

        push    ebp 
        mov     ebp,esp 
        sub     esp,%1 

%endmacro

%macro  epilogue 1 

        mov     esp,ebp
        pop     ebp 
        ret

%endmacro

The argument supplied is how much room you'd like to reserve on the stack.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top