Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missed optimisation: lea that evaluates to same offset as sp #110

Open
ecm-pushbx opened this issue Jun 4, 2022 · 1 comment
Open

Missed optimisation: lea that evaluates to same offset as sp #110

ecm-pushbx opened this issue Jun 4, 2022 · 1 comment

Comments

@ecm-pushbx
Copy link

Something I noticed in FDOS/kernel#81 (comment) it uses lea ax, [bp - 18h] just after a sub sp that computes the exact same address.

7C80:2E7E 55                push    bp
7C80:2E7F 89E5              mov     bp, sp
7C80:2E81 83EC18            sub     sp, +18
7C80:2E84 8D46E8            lea     ax, [bp-18]
7C80:2E87 50                push    ax
7C80:2E88 B81200            mov     ax, 0012
7C80:2E8B 50                push    ax
7C80:2E8C E844D3            call    01D3
-
7C80:2E8F 8B46E8            mov     ax, [bp-18]
7C80:2E92 89EC              mov     sp, bp
7C80:2E94 5D                pop     bp
7C80:2E95 C3                retn
@ecm-pushbx
Copy link
Author

NB the optimisation allowed here is to use mov ax, sp. The choice to use push sp would not be portable as its behaviour differs depending on the CPU, so is not an alternative here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants