开发者

Size optimizations for Assembly

What other optimizations, like the one presented here `testl` eax against eax? can one apply in order to reduce code size?

I am interested especially in one-line optimizations like using test eax, eax instead of cmp eax, 0.

Tha开发者_JS百科nks.


Moving constant signed bytes (-128 to 127) to registers can be used with push and pop to save a couple of bytes.

6A09         push byte 9     ; Push byte 9 on stack
58           pop eax         ; Pop into 32-bit eax

That's three bytes in comparsion to the mov five byte equivalent

B809000000   mov eax, 9


Moving some constants into registers can be done more efficiently without using mov. For instance, to move zero into rax:

xor eax, eax

Or to set rax to one:

xor eax, eax
inc eax

eax (rather than rax) can be used since the upper half of rax is implicitly cleared (thanks for the comment)


I found another one:

add eax, 1

replaced with

inc eax
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜