ISA & Assembly
What is the main purpose of defining a calling convention?
- ATo standardize function names and make programs readable
- BSo that separately compiled functions and libraries can pass arguments and return values correctly
- CTo require OS permission each time a function is called
Show answer and explanation
Answer: B. So that separately compiled functions and libraries can pass arguments and return values correctly
A calling convention specifies which registers hold arguments, where return values go, which registers the callee may clobber and how the stack is used. Because of this agreement, libraries built by different compilers, or assembly functions combined with C functions, work together correctly. The calling convention is a key part of the ABI (application binary interface).
- A. It is not a naming rule.
- B. Correct. It is a machine-level agreement.
- C. The OS is not involved in function calls.