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

Bitshift bug in SRA #9

Closed
agustiza opened this issue Aug 21, 2023 · 0 comments · Fixed by #10
Closed

Bitshift bug in SRA #9

agustiza opened this issue Aug 21, 2023 · 0 comments · Fixed by #10

Comments

@agustiza
Copy link
Contributor

Hi!

Thanks for sharing your project!

Just so you know it's being used as an educational tool as an intro for embedded devices in an Argentine college to great effect.

That said I couldn't help but notice a small bug. I'll push a quick PR if you don't mind.

Description

On the SRA instruction. This line specifically, seems it's shifting the carry flag to the right instead of to the left.

LOAD s0, 41   ;0100 0001
SR0 1              ;Set carry flag to 1
SRA s0            ;Should be 1010 0000 but is instead 0010 0001

Here's the snippet of code that surfaced this bug. Swaps MSB and LSB using shifts and carry only

address 0

load s0,59
output s0,0

;shift and load MSB into an aux register
sl0 s0
output s0, 0
addcy s1, 0

;shift back again and load LSB into an aux register
sr0 s0
output s0, 0
sr0 s0
output s0, 0
addcy s2, 0

;load MSB aux reg into carry so that we can SLA in the bit
sr0 s1
sla s0
output s0, 0

;shift back and load LSB aux reg into carry so that we can SRA in the bit
sl0 s0
output s0, 0
sr0 s2
sra s0 ;bugged line, should be shifting the C flag from the left
output s0, 0
agustiza added a commit to agustiza/PicoBlaze_Simulator_in_JS that referenced this issue Aug 21, 2023
FlatAssembler added a commit that referenced this issue Aug 21, 2023
fix: Fixes #9 SRA carry flag is set on the MSB instead of LSB
FlatAssembler added a commit that referenced this issue Oct 6, 2023
fix: Fixes #9 SRA carry flag is set on the MSB instead of LSB
FlatAssembler added a commit that referenced this issue Apr 7, 2024
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

Successfully merging a pull request may close this issue.

1 participant