<<Note that the code shown in this post is using the NASM syntax (first operand is destination).>>
I can either zero the destination 4-byte register and then copy in the two bytes like this:
Code:
xor eax,eax
mov eax,[mem_ptr]
or I can do it in one operation like this:
Code:
movzx eax,[mem_ptr]
While the MOVZX opcode takes only one line of assembly code to do 2 things, my question is if it's actually faster for the CPU to execute. Often times in programming, code that takes more lines to write seems to be faster to execute. It all depends on the number of clock ticks that are needed to execute the MOVZX instruction compared to the number of clock ticks that are needed to execute the 2 instrunctions XOR and then MOV (the sum of the clock ticks for each of these 2 added together).