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

Synthesize load instructions between register pairs (Z80, GB) #109

Open
Bananattack opened this issue Feb 3, 2021 · 0 comments
Open

Synthesize load instructions between register pairs (Z80, GB) #109

Bananattack opened this issue Feb 3, 2021 · 0 comments

Comments

@Bananattack
Copy link
Collaborator

Bananattack commented Feb 3, 2021

(On Z80, GB, but could maybe pertain to other hardware) It would be nice if Wiz could automatically decompose load instructions on register pairs into load instructions on the individual parts, when a more suitable instruction doesn't exist.

As a simple example, this instruction isn't possible, because there is no load instruction that moves from one 16-bit register to another.

hl = bc;

This annoyingly produces an error. To a newcomer, they may think they need push and pop to load hl with bc, like so:

push(bc);
hl = pop();

But this isn't the most efficient way, and requiring temporary stack memory like this moves this particular step into something Wiz will never do implicitly.

Specifically for hl, there's this possibility, but this is also not the most size or cycle-efficient way:

hl = 0;
hl += bc;

There's a much more straightforward method. 16-bit registers (excepting SP and AF) can be split into their 8-bit parts. Load instructions exist between the general 8-bit registers, so hl = bc can be accomplished like this:

l = c;
h = b;

Wiz could automatically decompose the missing 16-bit load instruction into two 8-bit load instructions. Since this is the most efficient way to synthesize this, and since no registers other than those named in the assignment are accessed, there shouldn't be problems to do this.

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

No branches or pull requests

1 participant