Subroutines Flashcards

1
Q

What are the characteristics of an open(inline) subroutine?

A
  1. Code is inserted inline wherever the subroutine is invoked
    2.Arguments are passed in/out using registers
  2. Efficient, since branching and returning is avoided
  3. Suitable only for short subroutines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are open(inline) subroutines invoked and defined?

A

By use of m4 Macros
ie. define(cube, `mul $2 $1 $1, mul $2, $1, $2’)
ie. invoked as cube(x19, x20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the characteristics of a closed subroutine?

A
  1. Machine code for the routine appears only once in RAM
  2. When invoked, control “jumps” to the first instruction of the routine
  3. When finished, control returns to the next instruction in the calling code
  4. Arguments are placed in registers or the stack
  5. Slower than open routines, because of calling/returning
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

(T/F)Arguments to subroutines are considered as local variables

A

True
The subroutine may change their value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 parameters to pass parameters to subroutines?

A

By-value, By-reference, Using the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the process of invoking a closed subroutine?

A
  1. branch to the subroutine using ‘bl subroutine’
  2. Return address is stored in the Link Register(x30)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the stp instruction do?

A

Creates a frame record in each function’s stack frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a pointer argument?

A

The address of the variable is passed to the subroutine. The called subroutine dereferences the address, to manipulate the variable being pointed to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What registers are argc and argv[] passed into?

A

argc is passed into w0/x0, and the address for argv[] is passed into x1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is a structure returned?

A

A struct’s values are stored in a memory location specified by x8, which is provided before the function call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly