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

XOR/AND not clearing out the OF flag when needed #6

Closed
ssm951 opened this issue Nov 4, 2020 · 1 comment
Closed

XOR/AND not clearing out the OF flag when needed #6

ssm951 opened this issue Nov 4, 2020 · 1 comment

Comments

@ssm951
Copy link

ssm951 commented Nov 4, 2020

According to the CS:APP book 3rd edition, section 3.6.1, it is stated "For the logical operations, such as XOR, the carry and overflow flags are set to zero". To my understanding, other than not having the carry flag, y86 should have the same behavior on condition codes as x86.

Currently, if you do something like an addq that sets the overflow flag, the xorq instruction does not clear it. This is an easy fix in the instr.js file, line 81, where you can first set OF to zero before going into the switch statement.

Here is an example of a .ys code that reflects the discrepancy with the book stated above:

irmovq scratch, %rax
rrmovq %rax, %rbx
rmmovq %rbx, 0x8(%rax)
irmovq 0x9, %rax
irmovq 0x7fffffffffffffff, %rbx
addq %rbx, %rax
xorq %rax, %rax 
halt

scratch:

@ssm951
Copy link
Author

ssm951 commented Nov 9, 2020

Fixed by the approval of this pull request: #7

Thanks @boginw for keeping up with this project. We use this in our university to teach students about assembly code.

@ssm951 ssm951 closed this as completed Nov 9, 2020
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

1 participant