Jumps, Subroutines, Coroutines Flashcards
What is a jump? Why are they used?
A jump is a control statement that is used to control the flow of the program through manipulation of the Program Counter.
What are jumps used in conjunction with?
Control statements such as if, loops and switches.
List all of the jump statements…
Break, continue, goto.
How do we specify where we want goto to jump to?
Create a specified label at the destination.
What is the program counter? Where does it point?
A small register that points to the address of the currently executing statement.
What is goto mostly used for?
Catching complex errors?
Why is goto good for error and exception handling?
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.
Is it good practice to use goto?
No, because it can lead to complex, unstructured and disorganised code.
What is meant by program state? What does it consist of?
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.
What components are within the Virtual Address Space? Define each…
Code -> The executing program code.
Data -> Static variables.
Stack -> Execution of the stack program.
Heap -> The memory to be dynamically allocated.
What are the registers that operate within the program state?
base pointer, stack pointer, program counter.
Explain how setjmp and longjmp work in conjunction…
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.
What are setjmp and longjmp mainly used for?
Exception handling.
What does setjmp return?
If called directly, it returns 0. If called by longjmp, it returns the value passed in the buffer of longjmp.
Define coroutine and subroutine…
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.