Ok, here's a weird one for ya. I'm trying to learn assembler in linux, bsd, unix, whatever... well, i was playing around, and i wrote a few code snippets in c and c++ to see what they would compile to, and this is waht i got, first the code snippits:
now after compiling it ran just as you would expect, and i ran as on the add.S file to get an a.out, then used g++ to assemble and link the rest. It ran fine... I dont get it though, where in any of that does it do an add? I dont see an add instruction anywhere in there, yet it adds the numbers when you run it, so i'm confused....
Anyone know how this works?
-----------------
Crackez
code:<HR>Code:add.C: int add (int a, int b) { return a + b; } addm.cpp: #include<iostream> int add(int, int); int main() { int a, b; cin >> a >> b; cout << add(a, b) << endl; return 0; } ----------------------------------- and after compiling: add.S: .file "add.C" gcc2_compiled.: ___gnu_compiled_cplusplus: .text .align 4 .globl _add__Fii .def _add__Fii; .scl 2; .type 32; .endef _add__Fii: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax movl 12(%ebp),%ecx leal (%ecx,%eax),%edx movl %edx,%eax jmp L2 jmp L3 jmp L2 .align 4 L3: L2: movl %ebp,%esp popl %ebp ret
now after compiling it ran just as you would expect, and i ran as on the add.S file to get an a.out, then used g++ to assemble and link the rest. It ran fine... I dont get it though, where in any of that does it do an add? I dont see an add instruction anywhere in there, yet it adds the numbers when you run it, so i'm confused....
Anyone know how this works?
-----------------
Crackez