jd12345 said:
Computer looks like a magic box to me at the moment - i have no idea how it works fundamentally. Do they teach at undergraduate level that how a computer actually works at the deepest level?
And what approach should i take while learning programming for the first time? Should i just learn the computer language without knowing how it works?
Well you have hardware and software levels and each level has its own sub-levels and so on.
The lowest level for software is machine-language and the native instruction set for the platform. Each platform has its own instruction sets, architecture design, memory model, and so on.
Everything in terms of software is built on top of this and with modern programs and operating systems, we are talking millions upon millions of lines of code in something like C or C++ (many millions) especially for operating systems.
The main way a computer works is that the code is executed top-down where instructions get processed in a sequential order and that the execution responds one execution at a time. There are architecture issues to take into account but this is the basic model. Basically you have an instruction pointer that changes based on the previous instruction and you execute each new instruction.
In terms of what you deal with you have registers and memory. The CPU deals with registers in the quickest possible manner and you load things from memory into registers to do stuff and then write the contents of the register back to memory. This is basically how things get done on the hardware level, but it's not exactly like this due to some architecture issues and design/feature issues.
Now you've got your memory which is basically your RAM and also a few other types. In terms of accessing your video card, hard-drive and other hardware, you use things like interrupts, I/O ports, and things built on top of this like DMA (Direct Memory Access) Controllers. I/O port access is done through the instructions IN and OUT on normal x86 architectures (standard PC's).
This is the basic idea of software although it's not detailed or complete, but it should help you understand what is going on.
In terms of hardware this is again different: you basically have lots of components built on logical gates and you have to deal with topics like synchronization and the use of clocks to co-ordinate everything, as well as making sure the hardware is reliable enough to do what it's meant to do.
Then you've got on top of this physics and material science issues for that scope as well as all the design and engineering issues for the actual circuitry specifics.
Again this is an oversimplification, but it should give you an idea of how it works at least at one level.
If you do computer engineering, you will learn how this all works at the lower levels including the hardware and the low-level software. You probably won't learn much about material science issues and some physics issues (but you will learn about other physics issues) and you won't learn about more of the high level computer science theory unless you take specific electives in this.
If you want to learn computer languages, start with something like C or C++ and remember the top-down rule. Remember that you keep going down unless you are branching (if statements), looping (for, while statements), or calling functions ( example - foo()). The rules are: for branching is basically to execute something if the condition is met, for looping you stay in the loop until the exit condition is finished, and for functions you return to the last code scope (i.e. the code that called the function) and continue on top to bottom.
For multi-threaded, parallel coding it's a little different but don't worry about learning that just yet!