Browse Source

Fixed the flags to match 8085 and created the add and subtract methods

master
Raphael Roberts 6 years ago
parent
commit
b125ab17a0
  1. 37
      register.py

37
register.py

@ -48,10 +48,41 @@ class Register:
class Acumulator(Register):
positive_flag = False
negative_flag = False
zero_flag = False
carry = False
carry_flag = False
parity_flag = False
def add(self, register):
def set_flags(self):
self.negative_flag = False
self.zero_flag = False
if self.get_signed() < 0:
self.negative_flag = True
if self.get() == 0:
self.zero_flag = True
v = self.get()
self.parity_flag = True
while v > 0:
if (v & 1) == 1:
self.parity_flag = not self.parity_flag
v >>= 1
def add(self, register: Register):
self.value += register.value
if self.value.bit_length() > self.n_bits:
self.carry_flag = True
self.trucate()
self.set_flags()
def sub(self, register: Register):
self.negate()
self.add(register)
self.negate()
self.set_flags()
def shift_right(self, through_carry=True):
pass
def shift_left(self, through_carry=True):
pass
Loading…
Cancel
Save