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

Do 8XY6 and 8XYE change VY as well? #4

Closed
dkim opened this issue Aug 13, 2019 · 6 comments
Closed

Do 8XY6 and 8XYE change VY as well? #4

dkim opened this issue Aug 13, 2019 · 6 comments

Comments

@dkim
Copy link

dkim commented Aug 13, 2019

Can you clarify whether the 8XY6 and 8XYE instructions change the VY register as well? The table below in your "Mastering CHIP-8" (and the Wiki) appears to mean that they change only the VX register: VX = VY >> 1 and VX = VY << 1.

8XY6: Store the value of register VY shifted right one bit in register VX ...
8XYE: Store the value of register VY shifted left one bit in register VX ...

On the other hand, the paragraph below the table gives an impression that register VY has to be modified as well: VX = VY = VY >> 1 and VX = VY = VY << 1.

It is a common misconception when programming in CHIP-8 to assume that the VX register is shifted by this instruction, and VY remains unmodified.

I found that Octo, a popular CHIP-8 assembler, uses the first interpretation while there are some documentation that supports the second one: Chip-8 on the COSMAC VIP and the previous version of the CHIP-8 page on Wikipedia.

Anyway, thank you for your great documentation!

@tobiasvl
Copy link

tobiasvl commented Nov 1, 2019

Yes, it seems that VY would be shifted in the original CHIP-8 interpreter, according to this great write-up about it.

This could help explain why the "common misconception" arose in SCHIP in the first place – it doesn't make much practical sense to "return" both VX and VY with the same value, but that does seem to be what it originally did.

Great catch, this is something I haven't seen much discussion about before.

@dkim
Copy link
Author

dkim commented Nov 2, 2019

The table in the write-up says that VY as well as VX should be updated, but the flowchart on the same page says that the result of the operation should be saved in only VX. :S

@mattmikolay
Copy link
Owner

Interesting! It should be straightforward to write a small CHIP-8 program that verifies how 8XY6 and 8XYE are implemented on a given emulator, i.e. whether or not they correctly change VY as on the COSMAC VIP. I'll work on this once I have some free time!

@dkim
Copy link
Author

dkim commented Nov 2, 2019

For now, I believe that the original CHIP-8 interpreter on the COSMAC VIP changed only VX: VX = VY >> 1 and VX = VY << 1. The flowcharts on "VIPER, Volulme 1, Issue 2" and "Chip-8 on the COSMAC VIP", which appear to have been written by disassembling the machine code for the CHIP-8 interpreter listed in the original manual (RCA COSMAC VIP CDP18S711 Instruction Manual, Appendix C - CHIP-8 Interpreter), say so.

@tobiasvl
Copy link

tobiasvl commented Nov 2, 2019

Yeah, it seems that's the case after all. I just tried out in Emma 02, which I have to assume is accurate, and it does leave VY intact.

@mattmikolay
Copy link
Owner

Thanks for verifying, @tobiasvl. I've updated the instruction set on the wiki to note that VY is unchanged.

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

No branches or pull requests

3 participants