YJDoc2 / 8086-emulator-web

Repository for 8086 emulator web implementation
Apache License 2.0
222 stars 26 forks source link

[Bug] Flag CF After executing SHR #17

Closed Narukara closed 2 years ago

Narukara commented 2 years ago

I am not sure if this is a bug since I am an 8086 beginner.

I am using the 8086 emulator on the web page and I found a problem:

When I execute:

start:
MOV CX, 0x0004
MOV DX, 0x0010
SHR DX, CL

Finally CF will be set to 1.

And when I execute:

start:
MOV CX, 0x0004
MOV DX, 0x000F
SHR DX, CL

Finally CF will be set to 0.

I believe this violates the definition of the SHR instruction.

YJDoc2 commented 2 years ago

Hey, Thanks for reporting this :+1: Hope you are finding this emulator useful.

This behavior is indeed incorrect. The CF should be set to exactly opposite values. As the 8086 family manual states that

CF will contain value of the last bit shifted out of the destination operand

Thus in first example the last value will be 0, and in second example will be 1. I have figured out where the error lies in the code logic. Also as the code for different shifts is taken after each other (as it is quite similar) maybe this issue also affects other shifts as well. I am a bit busy for few days, so I will fix this few days later.

Let know if you still have doubts or issues.

Thanks for reporting :)

YJDoc2 commented 2 years ago

Hey I have updated the core lib, as well as the dependency in this repo. Now this should give the results as expected. Please check once, and if fine, close the issue. Thanks for reporting!