ISA & Assembly

What is the main purpose of defining a calling convention?

  1. ATo standardize function names and make programs readable
  2. BSo that separately compiled functions and libraries can pass arguments and return values correctly
  3. 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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. In the standard RISC-V calling convention, which registers pass integer arguments and return values?
  2. In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?
  3. In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?
  4. In the RISC-V calling convention, t0-t6 are caller-saved. If a function wants to keep using a value in t0 after calling another function, what should it do?
  5. A function that calls no other functions (a leaf function) often does not need to save ra on the stack. Why?