Today, I get the answer of "compare the instructions between 'xorq %rdx, %rdx' and 'movq $0, %rdx' from cs-app", it says that front one need 3 bytes and the last one need 7 bytes. And it also says "xorl %edx, %edx" need 2 bytes and "movl $0, %edx" need 5 bytes. But I don't know how to compute it. Could you please help me?
Asked
Active
Viewed 31 times
0
-
2By far the easiest way if you don't already know the encodings is to feed them to an assembler and look at disassembly, e.g. in `objdump -drwC`, so the machine code bytes for each instruction will be on the same line as it. (GAS doesn't optimize `xor %rdx,%rdx` into the equivalent but shorter `xor %edx,%edx` for you, so unlike NASM it will actually reproduce those unnecessarily long instructions.) – Peter Cordes Oct 13 '22 at 13:01
-
1Also for this specific example, [What is the best way to set a register to zero in x86 assembly: xor, mov or and?](https://stackoverflow.com/q/33666617) explains why `xorq` is longer (REX prefix). For the `mov`s, see https://stackoverflow.com/questions/4829937/how-many-ways-to-set-a-register-to-zero/32673696#32673696 - the comments on the three integer MOV instructions in my answer correspond to this `movl`, `movq`, and 10-byte `movabsq $0, %rax`. – Peter Cordes Oct 13 '22 at 13:23