UMBC CMSC 211

UMBC | CSEE


CPU Help with Procedures

Once again, our hardware brethren have come to our aid! There are two new instructions, since the 80186. The two instructions are enter and leave According to the Microsoft MASM Reference manual, the enter: QUOTE

Creates a stack fram for a procedure that receives parameters passed on the stack. When immed16 is 0 ENTER is equivalent to push bp, followed immediately by the mov bp, sp. The first operand of the ENTER instruction specifies the number of bytes to reserve for local variables. The second operand specifies the nesting level for the procedure. The nesting level should be 0 for languages thto do not allow access to local variables of higher-level procedures (such as C, Basic, and FORTRAN). See the complementary instruction LEAVE for a method of exiting from a procedure. UNQUOTE

OK, what does it say about LEAVE:

QUOTE Terminates the stack frame of a procedure. LEAVE reverses the the action of a previous ENTER instruction by restoring SP and BP to the values they had before the procedure stack frame was initialized. LEAVE is equivalent to mov sp, bp, followed by pop bp. UNQUOTE


UMBC | CSEE