LOCAL pArray:PTR WORD ; pointer to an array. myProc PROC, ; procedure[r]
(1)CSC 221
Computer Organization and Assembly Language
Lecture 24:
(2)Lecture 23: Review
Assembly Implementation of:
• Shift and Rotate Instructions
– Logical Shifts and Arithmetic Shifts – SHL and SHR Instruction
– SAL and SAR Instructions – ROL and ROR Instruction – RCL and RCR Instructions – SHLD/SHRD Instructions
(3)Lecture 23: Review
Assembly Implementation of:
• Multiplication and Division Instructions
– MUL Instruction – IMUL Instruction – DIV Instruction
– Signed Integer Division
(4)Lecture Outline
• Local Variables • Stack Parameters
– Register vs Stack Parameters – INVOKE Directive
– PROC Directive – PROTO Directive
– Passing by Value or by Reference – Parameter Classifications
(5)Lecture Outline
• Stack Frames
– Memory Models
– Language Specifiers
(6)Terminologies
• Programming languages use different terms to refer to
subroutines :
– In C and C++, subroutines functions – In Java, subroutines methods
– In MASM, subroutines procedures
• Values passed to a subroutine by a calling program are
called arguments
• When the values are received by the called subroutine,
(7)LOCAL Directive
• A local variable is created, used, and destroyed
within a single procedure.
• The LOCAL directive declares a list of local
variables.
– immediately follows the PROC directive – each variable is assigned a type
• Syntax:
LOCAL varlist
Example:
MySub PROC
(8)Local Variables
LOCAL flagVals[20]:BYTE ; array of bytes
LOCAL pArray:PTR WORD ; pointer to an array
myProc PROC, ; procedure
LOCAL t1:BYTE, ; local variables
(9)MASM-Generated Code (1 of 2)
BubbleSort PROC
LOCAL temp:DWORD, SwapFlag:BYTE .
ret
BubbleSort ENDP
BubbleSort PROC push ebp
mov ebp,esp
add esp,0FFFFFFF8h ; add -8 to ESP .
mov esp,ebp pop ebp
ret
BubbleSort ENDP
(10)MASM-Generated Code (2 of 2)
Diagram of the stack frame for the BubbleSort
procedure:
return address
EBP EBP [EBP - 4] ESP
temp