After studying this chapter you will be able to understand: Discuss basic concepts related to concurrency, such as race conditions, OS concerns, and mutual exclusion requirements; understand hardware approaches to supporting mutual exclusion; define and explain semaphores; define and explain monitors;. | CSC 221 Computer Organization and Assembly Language Lecture 26: Recursion and String Operations Lecture 25: Review Assembly Implementation of: Stack Parameters INVOKE Directive PROC Directive PROTO Directive Passing by Value or by Reference Example: Exchanging Two Integers Lecture 25: Review Assembly Implementation of: Stack Frames Explicit Access to Stack Parameters Passing Arguments by Reference (cont.) Lecture Outline Advanced Procedures: Recursion What is recursion? Recursively Calculating a Sum Calculating a Factorial String Primitive Instructions MOVSB, MOVSW, and MOVSD CMPSB, CMPSW, and CMPSD SCASB, SCASW, and SCASD STOSB, STOSW, and STOSD LODSB, LODSW, and LODSD Lecture Outline Selected String Procedures Str_length Procedure Str_copy Procedure Str_trim Procedure Str_ucase Procedure Recursion What is recursion? Recursively Calculating a Sum Calculating a Factorial What is Recursion? The process created when . . . A procedure calls itself Procedure A calls procedure B, which in turn calls procedure A Using a graph in which each node is a procedure and each edge is a procedure call, recursion forms a cycle: Recursively Calculating a Sum CalcSum PROC cmp ecx,0 ; check counter value jz L2 ; quit if zero add eax,ecx ; otherwise, add to sum dec ecx ; decrement counter call CalcSum ; recursive call L2: ret CalcSum ENDP The CalcSum procedure recursively calculates the sum of an array of integers. Receives: ECX = count. Returns: EAX = sum Stack frame: Recursively Calculating a Sum .code main PROC mov ecx,10 ; count = 10 mov eax,0 ; holds the sum call CalcSum ; calculate sum L1: invoke dwtoa, eax, addr disp1 ; display eax invoke StdOut, addr disp1 invoke ExitProcess,0 main ENDP ;------------------------------------------ CalcSum PROC ; Calculates the sum of a list of integers ; Receives: ECX = count | Returns: EAX = sum ;------------------------------------------ cmp ecx,0 ; check counter value jz L2 ; quit if zero add eax,ecx ; otherwise, add to sum dec ecx ; . | CSC 221 Computer Organization and Assembly Language Lecture 26: Recursion and String Operations Lecture 25: Review Assembly Implementation of: Stack Parameters INVOKE Directive PROC Directive PROTO Directive Passing by Value or by Reference Example: Exchanging Two Integers Lecture 25: Review Assembly Implementation of: Stack Frames Explicit Access to Stack Parameters Passing Arguments by Reference (cont.) Lecture Outline Advanced Procedures: Recursion What is recursion? Recursively Calculating a Sum Calculating a Factorial String Primitive Instructions MOVSB, MOVSW, and MOVSD CMPSB, CMPSW, and CMPSD SCASB, SCASW, and SCASD STOSB, STOSW, and STOSD LODSB, LODSW, and LODSD Lecture Outline Selected String Procedures Str_length Procedure Str_copy Procedure Str_trim Procedure Str_ucase Procedure Recursion What is recursion? Recursively Calculating a Sum Calculating a Factorial What is Recursion? The process created when . . . A procedure calls itself Procedure A calls procedure B, which in