Problem 3 (10 points): Register Calling Conventions One of the pieces of documen
ID: 3757315 • Letter: P
Question
Problem 3 (10 points): Register Calling Conventions One of the pieces of documentation that goes hand-in-hand with the ISA, is the Application Binary Interface, or the ABl. The ABl defines the rules that programmers who write in the specific ISA are to follow in order for their code to be compatible with functions written by other programmers. An integral part of the ABI is the calling conventions for the registers, these conventions define which registers are caller-saved and which ones are callee saved as well as their typical usage. If you look at the bottom right corner of the first page of the LEGv8 Reference Sheet on the website, you'll see the calling conventions for LEGv8. a. Based on this calling convention, which registers are caller saved? 13] b. Based on this calling convention, which registers are callee saved? [3] c. In your own words, explain why the ABI isn't part of the ISA. [4]Explanation / Answer
Assembly, Applications, & Alliteration” by Xeno Kovah and it’s been wonderful so far. It is a repeat of many things I am already aware of but there has been a lot of new things learnt. I might write about parts of what I learnt from the course but not everything. This post is about x86 register, conventions associated with them as well as function call conventions.
x86 registers
There are 9 registers in x86: EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP and EIP. These are mostly derived by prefixing E(Extended) to their 16 bit equivalents.
EAX: The accumulator. This register typically stores return values from functions.
EBX: This register is typically the pointer to the base of an array.
ECX: This is typically used as a counter: loops, iterating through an array etc.
EDX: Commonly used as a supporting register. For example, 64 bit return values are returned in EDX:EAX in the code generated by 32 bit compilers.
ESI: The source index for string operations.
EDI: The destination index for string operations.
EBP: This register points to the base of the current function’s stack frame.
ESP: This register points to the top of the current function’s stack frame.
EIP: This register points to the address of the next instruction. This is the only instruction that cannot be manipulated by any instruction except call and ret.
x86 register conventions
Caller save registers: These registers have to be saved by the caller function if it wants to preserve their values. EAX, ECX and EDX are caller save registers. EAX is usually modified by the callee in almost all cases(it holds the return value remember?)
Callee save register: These registers have to be saved by callee function if it will modify these registers. EBP, EBX, EDI and ESI are callee save registers. EBP is usually modified by the callee in almost all cases(it points to the base of the function’s stack frame remember?)
Calling conventions
There are multiple ways to pass the parameters to the callee function. Here I will discuss 3 such conventions.
1. CDECL convention: C Declaration. In this convention, the parameters are passed in the reverse order(i.e. from right to left) on the stack by the caller and the caller is responsible for cleaning up the parameters from the stack i.e. it is caller clean up. GCC follows this convention. I think even MS Visual Studio does-at least the free Express edition.
2. STDCALL convention: Standard Call. This is exactly same as CDECL except that the callee is responsible for removing the parameters from the stack i.e. it is callee clean up. The Win32 API follows this convention.
3. FASTCALL convention: I have never encountered this convention before but the idea is that some parameters are passed through the registers and rest through the stack. There is no universal standard-each compiler designer has a different implementation of the convention. This is also callee clean up
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.