Originally posted by: Markbnj
Haha, the equivalent to those three calls to cout operator << in assembler isn't something to sneeze at. The loops... no big deal. But writing to stdout involves either making some assumptions about the location of the text buffer or firing off some interrupts.
In other words, I'm with George. And if you take degibson's (presumably tongue in cheek) advice you'll have some reading to do, even with that little bit of code, because all you'll see at the calls to cout is some register setup and call syntax. Trace into cout operator << and you'll really be in the thick of it.
Ahh... don't forget the magic of libraries! I'm sure the OP's HW wants him to throw some int 21h's around... but gcc won't do that ugliness. Check it out:
My foo.C:
1 #include <iostream>
2
3 using namespace std;
4
5 void foo() {
6 cout << "Bar";
7 }
g++ -c -S foo.C -o foo.S (I trimmed off the junk that g++ spits out, and the .asciiz definition of "Bar")
73 .type _Z3foov, @function
74 _Z3foov:
75 .LFB1401:
76 pushl %ebp
77 .LCFI9:
78 movl %esp, %ebp
79 .LCFI10:
80 subl $8, %esp
81 .LCFI11:
82 movl $.LC0, 4(%esp)
83 movl $_ZSt4cout, (%esp)
84 call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
85 leave
86 ret
Ugly, perhaps, but not horrible.

And no int 21h, sadly.
Edited to add Markbnj's quote.