def ADD(register): if not validate.validate_reg(register): print "Invalid Register: %s" % register exit(1) a = int(registers.reg["A"], 16) if register == "M": b = extras.getPair('H', 'L') if extras.chkMemory(b): b = int(registers.reg[register], 16) else: print " Invalid Memory:", b exit(1) else: b = int(registers.reg[register], 16) t = a + b a = int(extras.getLowerNibble(format(a, '0x')), 2) b = int(extras.getLowerNibble(format(b, '0x')), 2) if not validate.validate_data(t): print "\n////-----OverFlow Detected----////\n" t = format(t, "02x") t = set_flags.setCarry(t) set_flags.setFlags(a, b, t, isAbnormalFlow=True) tmp = {"A": t[1:]} else: t = format(t, "02x") tmp = {"A": t} set_flags.setFlags(a, b, t) registers.reg.update(tmp)
def SUI(data): a = int(registers.reg['A'], 16) b = int(data, 16) res = a - b res = format(res, '02x') if not validate.validate_data(int(res, 16)): res = set_flags.setCarry(res) set_flags.setFlags(a, b, res, isAbnormalFlow=True) else: set_flags.setFlags(a, b, res) registers.reg['A'] = res
def ADI(data): a = int(registers.reg['A'], 16) b = int(data, 16) res = format((a + b), '02x') a = int(extras.getLowerNibble(format(a, '0x')), 2) b = int(extras.getLowerNibble(format(b, '0x')), 2) if validate.validate_data(int(res, 16)): registers.reg['A'] = res set_flags.setFlags(a, b, res) else: print "\n Overflow Detected ADI", data print "Register Data[A]:", registers.reg['A'] exit(1)