Jumps, Subroutines, Coroutines Flashcards

1
Q

What is a jump? Why are they used?

A

A jump is a control statement that is used to control the flow of the program through manipulation of the Program Counter.

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

What are jumps used in conjunction with?

A

Control statements such as if, loops and switches.

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

List all of the jump statements…

A

Break, continue, goto.

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

How do we specify where we want goto to jump to?

A

Create a specified label at the destination.

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

What is the program counter? Where does it point?

A

A small register that points to the address of the currently executing statement.

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

What is goto mostly used for?

A

Catching complex errors?

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

Why is goto good for error and exception handling?

A

Because if an error is caught, goto can jump to the end of the program, bypassing the remaining executions and closing down the program to prevent further errors.

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

Is it good practice to use goto?

A

No, because it can lead to complex, unstructured and disorganised code.

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

What is meant by program state? What does it consist of?

A

The program state refers to the virtual address space and current location of registers.
It consists of the the programs Virtual Address Space and the Registers that operate on the Stack within the space.

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

What components are within the Virtual Address Space? Define each…

A

Code -> The executing program code.
Data -> Static variables.
Stack -> Execution of the stack program.
Heap -> The memory to be dynamically allocated.

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

What are the registers that operate within the program state?

A

base pointer, stack pointer, program counter.

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

Explain how setjmp and longjmp work in conjunction…

A

When setjmp is called, the program state is saved at that address, and execution continues down the stack. When longjmp is called, the program counter returns to the setjmp address, and the program state changes to the state at setjmp, and execution continues.

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

What are setjmp and longjmp mainly used for?

A

Exception handling.

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

What does setjmp return?

A

If called directly, it returns 0. If called by longjmp, it returns the value passed in the buffer of longjmp.

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

Define coroutine and subroutine…

A

Coroutine -> A way of enabling concurrency through yielding. Functions yield to one another to change execution routine without returning.
Subroutine -> A calling function calls another function. The function called then executes a routine and returns to the calling function, at which point the calling function resumes original execution.

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

What do we use co-routines?

A

For computationally heavy processes such as game development. This is because code can be executed across multiple frames.

17
Q

In C, what is meant by a frame?

A

A frame is a piece on the call stack that encapsulates the data needed for the execution of that function.