Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 352 Lecture 17 Functions in Assembly. Functions + Assembly Review Questions? Branching Call / Jump Reminder exam on Friday, project due next Friday.

Similar presentations


Presentation on theme: "ITEC 352 Lecture 17 Functions in Assembly. Functions + Assembly Review Questions? Branching Call / Jump Reminder exam on Friday, project due next Friday."— Presentation transcript:

1 ITEC 352 Lecture 17 Functions in Assembly

2 Functions + Assembly Review Questions? Branching Call / Jump Reminder exam on Friday, project due next Friday

3 Functions + Assembly Outline Beyond the basics

4 Functions + Assembly Points to ponder So far you have seen the instructions available for the ARC machine Mapping between high level languages and assembly –Variables –Operations –Assignment –Conditionals –Loops –Arrays –Functions –Objects

5 Functions + Assembly Process How to take simple tools and build something complex Bootstrapping 101

6 Functions + Assembly A little buildup Addressing modes –How to get to memory –Why more than one?

7 Functions + Assembly ARC Methods Using the call instruction.begin.org 2048 f: ld %r1, %r2 ….org 0 main: … call f ! call routine at function f. ld [x], %r1  instruction that must be executed after f finishes. halt.end

8 Functions + Assembly Writing methods in ARC (2).begin.org 2048 f: ld %r1, %r2 … jmpl %r15+4, %r0.org 0 main: … call f ld [x], %r1 <- This is at memory address %r15 + 4. halt.end

9 Functions + Assembly Jumping Have ability to jump back / forth to blocks of code What capabilities are not made possible with this approach?

10 Functions + Assembly Registers Subroutine linkage with registers passes parameters in registers. High level language equivalent?

11 Functions + Assembly Memory Subroutine linkage with a data link area passes parameters in a separate area in memory. The address of the memory area is passed in a register ( %r5 here).

12 Functions + Assembly sethi Example: sethi 1, %r1 will load the number “1” in the 11 th position as follows: 0000000000000000000010000000000 The value in register %r1 is not 1!, It is 2 10 Hence, to load 1 into the register, we now need to shift the register by 10 bits to the right. srl 10, %r1 10 th position Purpose: set a value in a particular place

13 Functions + Assembly Shifty Shift right (srl) –Shift a register by a certain # of bits and store the result in another register (0s are padded) –srl 10, %r1 Shift left (sll) –Instead of the right, go left Why is shifting bits important?

14 Functions + Assembly Back to functions Limitations of each approach –Registers –Data link area Recursion Possible solutions

15 Functions + Assembly Function calls void f() { printf(“enter f”); g(); printf(“exit f”); } void g() { printf(“enter g”); h(); printf(“exit g”); } void h() { printf(“enter h”); i(); printf(“exit h”); } void i() { printf(“enter i”); i(); printf(“exit i”); } void main() { f(); } Write out what is called? Does this remind you of any particular data structure?

16 Functions + Assembly Terms Function activation –When its code is being activated –How many times is f activated? Function deactivation –When a function’s code goes from being active to non-active

17 Functions + Assembly OS / Languages Keeps track of what is active what is not Scheduling algorithms –Multi-tasking Scope of variables –Where do they live, when can they be accessed?

18 Functions + Assembly Review Functions / Assembly intro Next time –Stacks and the full implementation


Download ppt "ITEC 352 Lecture 17 Functions in Assembly. Functions + Assembly Review Questions? Branching Call / Jump Reminder exam on Friday, project due next Friday."

Similar presentations


Ads by Google