debjitbis08 / sim8085

Online 8085 simulator

Home Page:https://www.sim8085.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SBB command error

pranabendra opened this issue · comments

Initially, CY = 0. Upon running the following code,

	MVI A,01H
	MVI B,FFH
	SBB B
	STA 0020H
	HLT

the output is 02H in 0020H, which is correct.

Now, initially, when CY = 0, upon running this code,

	MVI A,01H
	MVI B,FFH
        STC
	SBB B
	STA 0020H
	HLT

the output is 03H in 0020H. But, the correct answer is 01H.

After studying the codebase of this project, I could relate this bug to these lines below :
In the 2nd case, STC puts CY = 1. Therefore,

if (state->cc.cy)

is true,
and hence,
rhs--;

Here, as value of B is rhs, I think rhs++ or lhs-- will give the correct results.