The MASM Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 09, 2010, 01:51:18 am

Login with username, password and session length
Search:     Advanced search
117346 Posts in 14003 Topics by 1654 Members
Latest Member: road_hog
* Home Help Search Login Register
+  The MASM Forum
|-+  General Forums
| |-+  The Workshop
| | |-+  Why ML always use LEAVE but not ENTER?
« previous next »
Pages: 1 [2] Print
Author Topic: Why ML always use LEAVE but not ENTER?  (Read 2121 times)
EduardoS
Member
*****
Posts: 132


Re: Why ML always use LEAVE but not ENTER?
« Reply #15 on: June 15, 2006, 01:03:11 pm »

enter is much more complex than leave, it don't just push ebp/mov ebp, esp:
Quote
temp_RBP = RSP // This value of RSP will eventually be loaded
// into RBP.
IF (temp_LEVEL>0) // Push "temp_LEVEL" parameters to the stack.
{
ENTER_START:
temp_ALLOC_SPACE = word-sized immediate specified in the instruction
(first operand), zero-extended to 64 bits
temp_LEVEL = byte-sized immediate specified in the instruction
(second operand), zero-extended to 64 bits
temp_LEVEL = temp_LEVEL AND 0x1f
// only keep 5 bits of level count
PUSH.v old_RBP
FOR (I=1; I<temp_LEVEL; I++)
// All but one of the parameters are copied
// from higher up on the stack.
{
temp_DATA = READ_MEM.v [SS:old_RBP-I*V]
PUSH.v temp_DATA
}
PUSH.v temp_RBP // The last parameter is the offset of the old
// value of RSP on the stack.
}
RSP.s = RSP - temp_ALLOC_SPACE // Leave "temp_ALLOC_SPACE" free bytes on
// the stack
WRITE_MEM.v [SS:RSP.s] = temp_unused // ENTER finishes with a memory write
// check on the final stack pointer,
// but no write actually occurs.
RBP.v = temp_RBP
EXIT

I never needed the second parameter, and i guess most of you neither, but it exists and the processor must intepret it,

Both leave and pop generates 2 uops, but pop can't be used alone to exit a stack frame.
Logged
Ossa
EW RF/Microwave Engineer
Member
*****
Gender: Male
Posts: 275



Re: Why ML always use LEAVE but not ENTER?
« Reply #16 on: June 15, 2006, 01:06:51 pm »

Yes, the second parameter is for nested procedures - almost no language supports them (not even Java IIRC) I think ML and Haskell might, but I'm rusty on those languages.

Ossa
Logged

Website (very old): ossa.the-wot.co.uk
savage
Macro-ologist
Member
****
Gender: Male
Posts: 78



Re: Why ML always use LEAVE but not ENTER?
« Reply #17 on: June 15, 2006, 04:01:30 pm »

Gotcha.  So it basically expands the complex instructions into simlpe instructions, which takes time.  So we may as well expand it in the first place.
Logged

Why is everyone always trying to get to point B?
Mark Jones
Drifting in the Abstract
Member
*****
Posts: 2302


=- Stargate Atlantis -=


Re: Why ML always use LEAVE but not ENTER?
« Reply #18 on: June 15, 2006, 08:15:49 pm »

...and omit the complex nesting. Cool. ThumbsUp
Logged

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08
Pages: 1 [2] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!