Its an outrage - 43 years old and no assembler skills! For lack of better
introductory material I am learning it by compiling up very simple bits of C
and using the Frank Hoffman's x86 Crash book and this
article<http://developers.sun.com/solaris/articles/x86_assembly_lang.html>to
work out whats going on. I don't want to be able to write it; just
read
it and keep track of the passed parameters etc. Below is the code, followed
by the assembler and comments on what I think is going on. My problem is
with asm lines 8-12 where some pointless dance seems to be occuring.
Do you have any idea what is happening here? Am I missing something really
obvious? Also I'm a bit queasy about line 3 of the assembler output. I can
remove lines 3,8-12 and it compiles and runs just fine without the extra
instructions but if thats systems performance and tuning, I'm off to join a
rock'n'roll band.
TIA
/d
int adder(int i, int j, int k)
{
int l;
l = i + j + k;
return l;
}
int main(void)
{
int x;
x = adder( 1, 2, 3);
return x;
}
/*
1. adder: pushl %ebp [ preserve contents of ebp ]
2. adder+1: movl %esp,%ebp [ set ebp to point to the top of the stack
]
3. adder+3: subl $0x8,%esp [ ? ]
4. adder+6: movl 0x8(%ebp),%eax [ ebp is framepointer, put the arg at
offset 8 and put it in a tmp register eax]
5. adder+9: addl 0xc(%ebp),%eax [ add the second arg to that temp
register ]
6. adder+0xc: movl 0x10(%ebp),%edx [ put the third argument in edx ]
7. adder+0xf: addl %edx,%eax [ add edx to eax - we have a result ]
8. adder+0x11: movl %eax,-0x8(%ebp) [ move the result to ebp-8 ]
9. adder+0x14: movl -0x8(%ebp),%eax [ move it back again ]
10. adder+0x17: movl %eax,-0x4(%ebp) [ move it into ebp-4 ]
11. adder+0x1a: jmp +0x0 <adder+0x1c> [no-op, start of new .section]
12. adder+0x1c: movl -0x4(%ebp),%eax [move it back again!]
13. adder+0x1f: leave [clean up activation record for this
proc]
14. adder+0x20: ret [ return to main() ]
*/
--
Dominic Kay
+44 780 124 6099
_______________________________________________
perf-discuss mailing list
[email protected]