tailieunhanh - Lecture Computer organization and assembly language: Chapter 16 - Dr. Safdar Hussain Bouk

In this chapter, we discuss various mechanisms to ensure the orderly execution of cooperating processes that share a logical address space, so that data consistency is maintained. | CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures Lecture 15: Review Elements are only added/removed to/from the top. LIFO (Last In First Out) structure. Managed by the CPU, using two registers: SS:ESP PUSH and POP Instructions PUSH syntax: PUSH r/m16 PUSH r/m32 PUSH imm32 POP syntax: POP r/m16 POP r/m32 10 9 8 7 6 5 4 3 2 1 Top Bottom Lecture 15: Review (cont.) PUSHFD and POPFD push and pop the EFLAGS register PUSHAD pushes the 32-bit general-purpose registers on the stack order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI POPAD pops the same registers off the stack in reverse order PUSHA and POPA do the same for 16-bit registers Lecture Outline Defining and Using PROCEDURES Creating Procedures Documenting Procedures Example: SumOf Procedure CALL and RET Instructions Nested Procedure Calls Local and Global Labels Procedure Parameters Flowchart Symbols USES Operator Creating Procedures Large problems can be divided into smaller tasks to make them more manageable. A procedure is the Assembly equivalent of a Java or C++ function. Following is an assembly language procedure named sample: sample PROC . . . ret sample ENDP Documenting Procedures Suggested documentation for each procedure: A description of all tasks accomplished by the procedure. Receives: A list of input parameters; state their usage and requirements. Returns: A description of values returned by the procedure. Requires: Optional list of requirements called preconditions that must be satisfied before the procedure is called. Example: SumOf Procedure ;--------------------------------------------------------- SumOf PROC ; ; Calculates and returns the sum of three 32-bit integers. ; Receives: EAX, EBX, ECX, the three integers. May be ; signed or unsigned. ; Returns: EAX = sum, and the status flags (Carry, ; Overflow, etc.) are changed. ; Requires: nothing ;--------------------------------------------------------- add eax,ebx add eax,ecx ret SumOf ENDP CALL and RET Instructions The CALL | CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures Lecture 15: Review Elements are only added/removed to/from the top. LIFO (Last In First Out) structure. Managed by the CPU, using two registers: SS:ESP PUSH and POP Instructions PUSH syntax: PUSH r/m16 PUSH r/m32 PUSH imm32 POP syntax: POP r/m16 POP r/m32 10 9 8 7 6 5 4 3 2 1 Top Bottom Lecture 15: Review (cont.) PUSHFD and POPFD push and pop the EFLAGS register PUSHAD pushes the 32-bit general-purpose registers on the stack order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI POPAD pops the same registers off the stack in reverse order PUSHA and POPA do the same for 16-bit registers Lecture Outline Defining and Using PROCEDURES Creating Procedures Documenting Procedures Example: SumOf Procedure CALL and RET Instructions Nested Procedure Calls Local and Global Labels Procedure Parameters Flowchart Symbols USES Operator Creating Procedures Large problems can be divided into smaller tasks to make them more manageable.

TÀI LIỆU LIÊN QUAN