implementing a simple adder and subtractor

This commit is contained in:
Thiago Auler 2017-11-14 15:54:56 -02:00 committed by GitHub
parent 1a7acdaf95
commit 57159c7484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,6 +67,35 @@ void fetch_operand()
} }
} }
void adjustNZ(db a)
{
if (a == 0) { Z_SET; } else { Z_UNSET;}
a = a >> 7;
if (a == 0) { N_SET; } else { N_UNSET; }
}
db adder(db a, db b)
{
db r = a + b;
// todo: adjust carry flag
// todo: adjust overflow flag
adjustNZ(r);
return r;
}
db subtractor(db a, db b)
{
db r = a - b;
// todo: adjust carry flag
// todo: adjust overflow flag
adjustNZ(r);
return r;
}
void adc() void adc()
{ {
// add memory to accumalator with carry // add memory to accumalator with carry