Hello,
When I first got into programming (in C) I always wondered how the computer
understood things like 'printf("Hello World\n")', 'if (a > b)', etc. After delving into assembly
language (using linux, as and gdb to step through C code), I realized that those high level statements are only for humans to read, and that another program (compiler) reads that
human code
if (a == b)
do this;
and turns it into something in assembly code:
mov 3, eax - this puts the first variable into the CPU's eax register
- eax will then equal -> 00000000 00000000 00000000 00000011
mov 2, ebx - ebx equals -> 00000000 00000000 00000000 00000010
cmp eax, ebx - the compare instruction compares these two registers, and then
sets a bit in the flags register that the following instruction checks:
je somewhere - je (jump if equal) checks to see if that certain bit is set or not and
either jumps to a certain address (somewhere) or doesn't.
And even 'mov 3, eax' is a higher level (for humans to read) statement. In memory 'mov 3, eax' and any other machine instruction would be something like:
00000000 00000000 00000101 11001011 (actual 1's and 0's would be different)
Learning some assembly language and seeing what's "under the hood" in C, etc.
will really help you understand how computers really just operate on 1's and 0's (actually HIGH and LOW voltages), and that certain instructions move 0's and 1's around in memory, and others compare 0's and 1's setting other 0's and 1's, etc.
The computer isn't "smart" and cannot "understand" anything. Smart people put logic
gates together in mind-boggling patterns that when fed high and low voltages in varying patterns push other logic gates, etc., and after millions of them fire off based upon what pattern was input, finally accomplish some small task somewhere in RAM or the CPU.
Alot of people probably know this already, but I just thought that if someone had
questions like I had when I first got into computers, they could use the info that learning how the machine operates at its base level will REALLY help you understand how computers and C work.
Thanks