I've just started to learn assembly in school, and we're starting to dive into registers and how to use them. A point that I can't seem to understand is how does the instruction pointer get the address of the next instruction? For instance take the following code:
nop
pushl %ebp
movl %esp, %ebp
subl $4, %esp
In the previous code the instruction pointer gets incremented after each line, and I'd like to know how does it know which instruction to do next (i.e mov,sub,push,...etc.)? Are all the previous instruction first loaded into RAM when we first run the program and the address of the first instruction (nop in this case) gets automatically loaded into eip, then it just goes over them one by one? Or am I missing something?
Any help is appreciated.