im curious as to if these 2 instructions one after the other would cause a problem in a computer while working with this code

mov eax,DWORD PTR[0x4343] // move a data stored in RAM into a register
add eax,eax                          // add eax with itself and store value in eax

wouldn't the CPU execute the addition instuctions before the actual value(due to latency/access time) got stored into the eax register??
Posted on 2010-12-11 12:03:02 by dougfunny
You may be thinking of reordering but that could not happen in this situation.
There are very strict rules regarding pipelining opcodes for execution.
For reading about Intel Core i7 for example you may wish to visit:
Posted on 2010-12-12 09:12:54 by p1ranha
An x86 CPU will process all instructions in a serial fashion at all times. That is, even though modern x86 CPUs can reorder instructions and execute multiple instructions in parallel, they will only do so if it doesn't affect the result.
In general a mov eax, can be executed in parallel with other instructions, but in this case, the add eax, eax has a dependency on the mov. Therefore the add will wait until the mov is completed.
If the add used another register, eg add edx, edx, it would execute in parallel with the mov, since they are not dependent.
Posted on 2010-12-14 02:15:38 by Scali

I'd like to write a letter to Michael Abrash about this question, yet I know what he would answer. ;)


CPU keeps instructions in order (well, the results of, in spite of superscalar architecture). Optimization is just about interleaving them in non-intrusive way.
Posted on 2010-12-14 14:49:23 by baldr
well, without pointing out the obvious (bugger.. im going to do it)..

mov eax,DWORD PTR[0x4343] // move a data stored in RAM into a register

would access an invalid area of memory (assuming the code is running in windows.. 32 bit or 64 bit doesn't matter).. and would thus crash...

wouldn't it? :)
Posted on 2010-12-15 08:55:14 by evlncrn8