Nepedia
Back to Discover
Fluent Reader
💻

Calling convention

technology Maturity 11-13 Next article →

In computer science, a calling convention is a set of rules for how different parts of a program talk to each other. When one part of a program, called the caller, asks another part, called a function, to do a job, they must follow a specific plan. This plan decides how to pass information, known as parameters, to the function. It also decides how the function sends its answer, called a return value, back to the caller. Without these rules, the different parts of a program would not understand each other. Using the right convention ensures that the whole program runs in a reliable way.

These rules work like a contract between the two parts of the program. The convention decides where to put the data being shared. Some rules use small, fast storage spots called registers. Other rules use a list in the computer's memory called a stack. The rules also decide the order of the parameters, such as passing them from left to right. They even decide who is responsible for cleaning up the mess after the job is done. This includes restoring the computer's environment so the caller can continue its own work.

Different types of computer hardware use different sets of rules. For example, the 32-bit x86 architecture often uses the stack to pass information. This is because it has a small number of registers available. However, the 64-bit x86-64 version has more registers to use. Because of this, both Microsoft's Windows convention and the AMD64 System V convention pass some arguments in registers. This change can make the computer work faster.

Other systems like ARM have very specific ways of using their registers. In the 32-bit ARM system, registers r0 through r3 are used to pass arguments and return results. The system also uses a special register called the link register, r14, to remember where to go back to. The 64-bit ARM system, or AArch64, uses even more registers, such as x0 through x7 for arguments. In the RISC-V system, the rules try to pass arguments in registers whenever it is possible. Some systems, like POWER, have so many registers that they can pass almost all arguments without using the stack.

Even though these rules are very low-level, they connect to things you might know. They are part of the application binary interface, or ABI. You can think of the ABI as the master set of rules for how software and hardware fit together. While a programmer might not see these rules every day, they are working in the background. They allow different languages and different parts of an operating system to work as one team. This teamwork is what allows your computer to run many different tasks at once.

465 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.