A
aarklon
Hi folks,
recently i read the book named assembly language step by step by Jeff
Duntemann.
in the chapter coding for linux, he has got a paragraph
named C calling conventions, which he describes as follows
1)
a function must preserve the values of ebx,esp,ebp,esi and edi 32 bit
registers. i.e although it may use those registers, when it returns
control to it's caller,the values of those registers must be the same
values they had before the function was called
2)
the contents all other G.P registers may be altered at will(in linux
this pointedly does not include the segmented registers, because it
being a protected mode operating system)
3)
A procedures return value is returned in EAX. if it's value is 32
bit or smaller.64 bit integer values are returned via EDX and EAX, with
the low 32 bits in EAX. floating point return values are returned via
floating point stack.strings structures and other items larger than
bits are returned by reference. i.e a function returns a pointer to
them in EAX.
4)
parameters passed to the procedure are pushed in the reverse order,
i.e given the C function(foo,bar,bas); bas pushed onto the stack first,
bar pushed onto the stack second.foo pushed onto the stack last.
5)
procedures do not remove parameters from the stack. the caller must
do that after the procedure returns.
either by popping the procedures Off(more commonly since it is
usually faster)
by adding an offset to the stack pointer ESP
well my question is how far these statements are correct.
please note that i am by no means an expert C programmer.i just want
gain a good understanding on these matters
recently i read the book named assembly language step by step by Jeff
Duntemann.
in the chapter coding for linux, he has got a paragraph
named C calling conventions, which he describes as follows
1)
a function must preserve the values of ebx,esp,ebp,esi and edi 32 bit
registers. i.e although it may use those registers, when it returns
control to it's caller,the values of those registers must be the same
values they had before the function was called
2)
the contents all other G.P registers may be altered at will(in linux
this pointedly does not include the segmented registers, because it
being a protected mode operating system)
3)
A procedures return value is returned in EAX. if it's value is 32
bit or smaller.64 bit integer values are returned via EDX and EAX, with
the low 32 bits in EAX. floating point return values are returned via
floating point stack.strings structures and other items larger than
bits are returned by reference. i.e a function returns a pointer to
them in EAX.
4)
parameters passed to the procedure are pushed in the reverse order,
i.e given the C function(foo,bar,bas); bas pushed onto the stack first,
bar pushed onto the stack second.foo pushed onto the stack last.
5)
procedures do not remove parameters from the stack. the caller must
do that after the procedure returns.
either by popping the procedures Off(more commonly since it is
usually faster)
by adding an offset to the stack pointer ESP
well my question is how far these statements are correct.
please note that i am by no means an expert C programmer.i just want
gain a good understanding on these matters