I know this is a very common question. But I have a different angle in my mind. I will just try to articulate it here.
From what I know, every instruction that a CPU executes, is in machine language and all CPU can do is do some arithmetic operations thanks to ALU and to its transistors (if we go at hardware level).
However this is easier to type than to comprehend it. So if all CPU does is adding, subtracting, etc., then how is a program, say a JAVA program saying print Hello World, executed with these arithmetic operations?
I mean how is this program converted into something that is just an addition for the CPU?
P.S. If this question is not applicable for this website then I apologise.
Okay. Thanks to all for answering this fast and with this enthusiasm. I thought its better to modify my question a bit than to go and comment to all answers and ask them again.
So here it is.
First, all have answered specifically w.r.t example of Hello World. This is my fault. I should have kept this generic. Hello world example brings in question of output devices and how its processing is not just limited to the CPU, which is rightfully brought up in your answers.
Also many of you brought to my notice that CPU does more than just addition. I agree with that. I just didn't write that and assumed it all the way. From what I understand, this is the process:
read the instruction from memory (using data and address buses and program counter stuff)
- store data in register inside CPU
- Now ALU does arithmetic operations, of course after decoding the instruction, or take a jump if its an if like instruction
- And then communicating with other resources if needed like with output device and so on. Processes beyond this are trivial for now.
So in step3 where CPU decodes an instruction and decides to do an arithmetic operation(here we are assuming that there is no other operation to be done like jump the current instruction..since arithmetic operations are mostly done..so we will stick to that) This is where my visualization ends. How an instruction from my program is just an arithmetic operation for CPU. It does that arithmetic operation and that instruction serves its purpose.
I hope I made myself clear this time.
P.S. I am taking a big assumption here that ALU is just not restricted to actual arithmetic operation we do in our programs, rather it executes all instructions ,which are now in binary form, by adding or subtracting e.t.c them to yield result that they are meant to yield. If I am wrong here than answers below correctly answer my question.