News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Enter / standard prolog

Started by Jokaste, December 08, 2017, 01:42:53 AM

Previous topic - Next topic

Jokaste

I wonder why assemblers use the prologue/epilogue pair and not Enter/exit pair?
Could you explain it, I am curious and I don't understand too.
thanks.
Kenavo
---------------------------
Grincheux / Jokaste

markallyn

Jokaste,

My novice understanding is that:
Quote
push rbp
mov rbp, rsp

is faster than:
Quote
enter

...and many programmers prefer higher speed.  However, difference is quite small, as I understand it.  The "leave" instruction (which I assume you intended when you wrote "exit") is apparently about tthe same speed as:

Quote
mov rsp, rbp
pop rbp

Regards,
Mark Allyn

Jokaste

Thanks for your (quick) answer.
I did not remember the mnemonic for LEAVE.
I will see if the number of bytes is the same and/or if the stack is aligned automatically.
There must be a reason for this pair of mnemonic exists.

Kenavo
---------------------------
Grincheux / Jokaste

felipe

Quote from: Jokaste on December 08, 2017, 03:04:32 AM
There must be a reason for this pair of mnemonic exists.

High level constructs to support high level languages. Probably compiler writers from ancient times would found much easier to use this instructions while programming. For example for nested procedures.

Have a look here for an aw27 authored topic related to this:
http://masm32.com/board/index.php?topic=6564.0.


Jokaste

QuoteProbably compiler writers from ancient times would found much easier to use this instructions while programming.

With actuall assemblers it seems (to me) that with all the macros (high Level, it seems) programmers don't write assembly code but macros code.


Thank you for the link, but it is not the purpose (nested procedures).
I am thinking about using variables from an other proc, like GoAsm does.
Kenavo
---------------------------
Grincheux / Jokaste

hutch--

Its generally the case that where you have to write high level code in assembler (API, CRT etc ...) the code takes so much longer than the entry and exit of the proc that it simply does not matter what you use to create the stack frame. The next factor is how would you test the entry and exit speed of a procedure when the techniques for constructing a stack frame do not lend themselves to loop code at all.

MASM has used the mnemonic LEAVE for many years but used the well known stack construction,

    push ebp        ; preserve base pointer
    mov ebp, esp    ; stack pointer into ebp

as the entry method for 32 bit procedures.

Here is a test piece for the 2 main methods of creating a stack frame in win64.

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

    include \masm32\include64\masm64rt.inc

    .data
      mtxt db "How D",0
      ttxt db "Title",0
      pmsg dq mtxt
      pttl dq ttxt

    .code

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

entry_point proc

    conout str$(rsp)," stack pointer on entry",lf


  ; --------------------------
  ; full manual procedure call
  ; --------------------------
;     mov rcx, 0
;     mov rdx, pmsg
;     mov r8, pttl
;     mov r9, MB_OK
;     call testproc

  ; ---------------------------
  ; proc call with shadow space
  ; ---------------------------
    ; invoke testproc,0,pmsg,pttl,MB_OK

  ; ------------------------
  ; same as full manual call
  ; ------------------------
    rcall testproc,0,pmsg,pttl,MB_OK

    conout str$(rax)," procedure return value",lf

    conout str$(rsp)," stack pointer on exit",lf

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

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

NOSTACKFRAME

testproc proc

;     push rbp                ; manually construct stack frame
;     mov rbp, rsp

    enter 80h, 0h

    sub rsp, 256            ; allocate local space on the stack

    call MessageBox         ; call API with arguments loaded in 1st 4 registers

    leave                   ; exit the stack frame

;     mov rsp, rbp            ; exit the stack frame
;     pop rbp

    ret

testproc endp

STACKFRAME

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

    end

comment ^

.text:0000000140001000 C8800000                   enter 0x80, 0x0
.text:0000000140001004 4883EC60                   sub rsp, 0x60

.text:0000000140001104 C9                         leave
.text:0000000140001105 C3                         ret

        versus

.text:0000000140001106 55                         push rbp
.text:0000000140001107 488BEC                     mov rbp, rsp
.text:000000014000110a 4881EC00010000             sub rsp, 0x80

.text:0000000140001117 488BE5                     mov rsp, rbp
.text:000000014000111a 5D                         pop rbp
.text:000000014000111b C3                         ret

^
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


This is the batch file to build it.

@echo off

set appname=manual

if exist %appname%.obj del %appname%.obj
if exist %appname%.exe del %appname%.exe

\masm32\bin64\ml64.exe /c %appname%.asm

\masm32\bin64\polink.exe /SUBSYSTEM:CONSOLE /MACHINE:X64 /ENTRY:entry_point /nologo /LARGEADDRESSAWARE %appname%.obj

dir %appname%.*

pause


felipe

Quote from: Jokaste on December 08, 2017, 05:38:03 AM
Thank you for the link, but it is not the purpose (nested procedures).

I'm just saying that the reason is basically a high level facility (from old times).

Jokaste

Thaks Hutch.
At the final time it is the same (number of bytes and speed).


Felipe, I began programming in 1980, in Cobol, APL and Assembler on BULL DPS6 and 7, on PDP and VAX, on NCR and on Digital mini-computers.
There was not DOS. It appears next year.
So the old times were when I began, I was 21 years old!
I am vexed, but I know it was not your intention, but suddenly you realized that you are an old man (58 years)!
Gamin


Philippe
Kenavo
---------------------------
Grincheux / Jokaste

hutch--

 :biggrin:

> but suddenly you realized that you are an old man (58 years)!

Ha ha, you are only a young fella.  :P

markallyn

Yup,  Hutch is right.  You're a wee one.  I'm 75.  I fought with Job Control Language on IBM 360 machines.  I lost.

Mark Allyn

Jokaste


Its mine on 2017/12/24 - 58 years.


I also new JCL on Punch Cards.
Kenavo
---------------------------
Grincheux / Jokaste

felipe

Quote from: Jokaste on December 08, 2017, 10:45:33 PM
Felipe, I began programming in 1980, in Cobol, APL and Assembler on BULL DPS6 and 7, on PDP and VAX, on NCR and on Digital mini-computers.
There was not DOS. It appears next year.
So the old times were when I began, I was 21 years old!
I am vexed, but I know it was not your intention, but suddenly you realized that you are an old man (58 years)!
Gamin


Philippe

Come on! I was just paraphrasing hutch, when he talks about the old DOS and old, antique instructions... :bgrin:

I wasn't saying to none of here old... :icon14:

felipe

Quote from: felipe on December 08, 2017, 02:25:58 PM
the reason is basically a high level facility

Btw, i said that, based on my reads from old (may i say old now?  :redface:) Intel manuals...And my memory from those reads.
:bgrin:

markallyn

Loved the cake! 

The best part of PCs compared to the old days is that one doesn't have to run up and down 4 flights of stairs with the deck of cards to fix a crumby line of Fortran.

Mark

Jokaste

And put the sticker on a band when it is left...
We went to the same school... :eusa_boohoo:
Kenavo
---------------------------
Grincheux / Jokaste