Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.

Similar presentations


Presentation on theme: "ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation."— Presentation transcript:

1 ITEC 352 Lecture 19 Functions in Assembly

2 Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation

3 Functions + Assembly Outline Functions in assembly Intro to JVM

4 Functions + Assembly Activation record An activation record is the memory allocated for each function activation. It contains the following data: return address memory for each local variable. memory for parameter values passed from caller function memory addresses of dynamically allocated memory.

5 Functions + Assembly Step 1 Consider a program: 1. int f( int x, int y) { 2. int a = 10; 3. int b = 5; 4. } 5. int main() { 6. int z = 5; 7. f(z, z) ; 8. } Initially the stack is empty. Execution of this program starts with the function main. Hence, an activation record for main is created as shown on the stack. PROGRAM STACK Return address Activation record for main. Memory for z Stack pointer (%sp)

6 Functions + Assembly Step 2 Consider a program: 1. int f( int x, int y) { 2. int a = 10; 3. int b = 5; 4. } 5. int main() { 6. int z = 5; 7. f(z, z) ; 8. } Next: The function “f” is invoked. We have to create and then push the activation record of “f”. However, before we do that, we have to create space for the actual parameters that we want to pass to function f (here it is z, z) PROGRAM STACK Return address Parameters to be passed to f. Memory for z Stack pointer (%sp) 5 5 return address In ARC this is stored in %r15 (address of line 8)

7 Functions + Assembly Step 2B Consider a program: 1. int f( int x, int y) { 2. int a = 10; 3. int b = 5; 4. } 5. int main() { 6. int z = 5; 7. f(z, z) ; 8. } Next: This is a continuation from previous slide. You can see that we now have the complete activation record of function f. PROGRAM STACK Return address Activation record of function f. Memory for z Stack pointer (%sp) 5 5 return address(%r15) a (value 10) b (value 5)

8 Functions + Assembly Final step Consider a program: 1. int f( int x, int y) { 2. int a = 10; 3. int b = 5; 4. } 5. int main() { 6. int z = 5; 7. f(z, z) ; 8. } Next: After f finishes execution its activation record is no longer “live” -- it is popped out. PROGRAM STACK Return address Program stack after f has finished execution. You can see that the local variables a and b are no longer accessible, Memory for z Stack pointer (%sp)

9 Functions + Assembly

10 Using stacks: in assembly language Stack pointer is stored in register %r14 A stack grows from high memory region to low memory region. Hence, when we push parameters onto the stack, we subtract a word from the current stack pointer to update its value.

11 Functions + Assembly I/O in Assembly Based on what you studied so far, how do you think I/O must be done in architecture? –E.g., how can a program read from, say a touchscreen?

12 Functions + Assembly I/O in Assembly Two choices: –Use special instructions to access each I/O device. Any disadvantages? –Use memory mapped I/O. What is memory mapped I/O?

13 Functions + Assembly Memory mapped I/O Devices are accessed as if they are memory locations. –Devices occupy sections of the address space where no other memory exists. 0 2 16 2 17 2 19 2 22 2 23 -4 Reserved for BIOS Add in Video Memory #1 Add in Video Memory #2 Unused Working memory System Stack Screen flash Touchscreen x Touchscreen y 2 24 -4 Stack Pointer I/O Space

14 Functions + Assembly Next: Example of assembly in the Java Virtual machine

15 Functions + Assembly Java Virtual Machine Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

16 Functions + Assembly

17 A Java Class File

18 Functions + Assembly Review Functions in assembly Intro to JVM + Bytecode


Download ppt "ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation."

Similar presentations


Ads by Google