3 ms·
> mov rsi, file_load_va + message: [...] This instruction ends up taking 10 bytes: two bytes for the opcode, and a full 8 bytes for the address. We can replace
by moonchild 5y ago
> mov rsi, file_load_va + message: [...] This instruction ends up taking 10 bytes: two bytes for the opcode, and a full 8 bytes for the address. We can replace this with mov esi, file_load_va + message to save 5 bytes
Nasm should perform this optimization automatically.
$ cat t.s
bits 64
mov rsi, 0xffffff
$ nasm -o t.o t.s
$ ndisasm -b 64 t.o
00000000 BEFFFFFF00 mov esi,0xffffff
$ nasm --version
NASM version 2.15.05 compiled on Sep 24 2020
- moonchild 5y agoAdditionally, there is an instruction ‘mov r64,imm32’ which nasm would select even if it did not have this crazy peephole; that is only 7 bytes, not 10 (rex, op, modr/m, id).
- yalue 5y agoOdd. For some reason, my version of nasm didn't do that, and instead opted for the lengthier 10-byte instruction shown in the article's objdump output. Maybe it's just an older version of nasm.