Week 8 - Jumps Flashcards
What does jmp mean?
Unconditional jump
What does jg mean?
Jump if greater
What does goto do?
Unconditionally jumps to a labelled statement
Write an example goto statement.
label:
<statements>
goto label;
</statements>
Why is goto considered harmful?
Because the flow of control in code is not clear
Spaghetti code is difficult to read and maintain
All programming constructs can be written without jumps
What does the state of an executing program depend on?
Virtual address space:
- code (the executing program code)
- data/BSS (static variables)
- stack (function return address, parameters, auto variables)
- heap (dynamically allocated variables)
Registers, including:
- sp (stack pointer)
- bp (base pointer)
- pc (program counter)
What does setjmp do?
Saves the contents of the registers to a buffer
What does longjmp do?
Restores the contents of the registers from a buffer
What is the difference between concurrency and parallelism?
Concurrency is multiple processes accessing one disk and sharing one CPU (with time slicing and context switching)
Parallelism is multiple processes running on separate CPUS
Are coroutines concurrent and/or parallel?
They are concurrent but not parallel
Give an example usage for coroutines.
Computer games to maintain an high framerate as the program can switch between the coroutine and the game loop