Beispiel #1
0
 def as_order(self):
     """
     >>> x = Value.from_order(('R', 16, 'S'))
     >>> x.as_order()
     ('R', 16, 'S')
     >>> x = Value.from_order(('T', 11, 'L'))
     >>> x.as_order()
     ('T', 11, 'L')
     """
     assert len(self.bits) == HALF_WORD_LENGTH
     op = io.edsac_to_letter(_bits_to_unsigned(self.bits[:5]))
     addr = _bits_to_unsigned(self.bits[
         ORDER_FORMAT['ADDRESS_START']:ORDER_FORMAT['ADDRESS_END']])  # 6:16
     sl = 'SL'[self.bits[ORDER_FORMAT['SL']]]
     return (op, addr, sl)
Beispiel #2
0
 def as_order(self):
     """
     >>> x = Value.from_order(('R', 16, 'S'))
     >>> x.as_order()
     ('R', 16, 'S')
     >>> x = Value.from_order(('T', 11, 'L'))
     >>> x.as_order()
     ('T', 11, 'L')
     """
     assert len(self.bits) == HALF_WORD_LENGTH
     op = io.edsac_to_letter(_bits_to_unsigned(self.bits[:5]))
     addr = _bits_to_unsigned(
         self.bits[
             ORDER_FORMAT['ADDRESS_START']: ORDER_FORMAT['ADDRESS_END']
         ]
     )  # 6:16
     sl = 'SL'[self.bits[ORDER_FORMAT['SL']]]
     return (op, addr, sl)
Beispiel #3
0
    def step(self):
        assert MIN_MEMORY_ADDR <= self.sequence_control < MAX_MEMORY_ADDR
        instr = self.get_memory(self.sequence_control)
        # debug
        if SHOW_RUNNNING_INSTRUCTION:
            print self.sequence_control, instr.as_order()

        op, addr, sl = instr.as_order()
        wide = (sl == "L")

        if op == "T":
            # TnS: m[n]=A; ABC=0
            # TnL: w[n]=AB; ABC=0
            a = self.get_accumulator(wide)
            self.set_memory(addr, a, wide)
            self.clear_accumulator()
        elif op == "H":
            # HnS: R += m[n]
            # HnL: RS += w[n]
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            r = m
            self.set_multiplier(r, wide)

        elif op == "E":
            # if A >= 0 goto n
            a = self.get_accumulator()
            if not a.is_negative():  # A >= 0
                self.sequence_control = addr - 1
        elif op == "G":
            # if A < 0 goto n
            a = self.get_accumulator()
            if a.is_negative():  # A < 0
                self.sequence_control = addr - 1

        elif op == "I":
            #  Place the next paper tape character
            #  in the *least* significant 5 bits of m[n].
            c = self.cards[self.next_char]
            self.next_char += 1
            v = io.ascii_to_edsac(c)
            self.set_memory(addr, Value.new_from_number(v))
            if DEBUG_IO:
                print "read", c, v

        elif op == "A":
            # AnS: A += m[n]
            # AnL: AB += w[n]
            m = self.get_memory(addr, wide)
            r = self.get_accumulator(wide)
            r = r + m
            self.set_accumulator(r, wide)
        elif op == "S":
            m = self.get_memory(addr, wide)
            r = self.get_accumulator(wide)
            r = r - m
            self.set_accumulator(r, wide)

        elif op == "V":
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            v = m.multiply(r)
            if wide:
                a = self.accumulator
            else:
                a = self.get_accumulator(wide=True)
            a.set(a + v)

        elif op == "N":
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            v = m.as_integer() * r.as_integer()
            v = m.multiply(r)
            if wide:
                a = self.accumulator
            else:
                a = self.get_accumulator(wide=True)
            a.set(a - v)

        elif op == "R":
            # Shift right
            num_shift = _calc_num_shift(instr)
            v = self.accumulator.as_integer()
            v = v >> num_shift
            self.accumulator.set_from_number(v)

        elif op == "L":
            # Shift left
            num_shift = _calc_num_shift(instr)
            v = self.accumulator.as_unsigned()
            v = v << num_shift
            self.accumulator.set_from_number(v)

        elif op == "U":
            # UnS: m[n]=A
            # UnL: w[n]=AB
            self.set_memory(addr, self.get_accumulator(wide), wide)

        elif op == "C":
            raise NotImplementedError
        elif op == "Y":
            raise NotImplementedError

        elif op == "O":
            # output
            if DEBUG_IO:
                code = self.get_memory(addr).as_charcode()
                print "output %s %s %s" % (
                    io.edsac_to_letter(code), io.edsac_to_figure(code), code)
            else:
                sys.stdout.write(
                    self.output(
                    self.get_memory(addr).as_charcode()))

        elif op == "X":
            pass  # no operation
        elif op == "F":
            raise NotImplementedError("Verify the last character"
                                      "output. What?")
        elif op == "Z":
            # finish
            return True
        else:
            raise AssertionError("Malformed Instruction:", instr.as_order())

        self.sequence_control += 1
        return False  # not finished
Beispiel #4
0
    def step(self):
        assert MIN_MEMORY_ADDR <= self.sequence_control < MAX_MEMORY_ADDR
        instr = self.get_memory(self.sequence_control)
        # debug
        if SHOW_RUNNNING_INSTRUCTION:
            print self.sequence_control, instr.as_order()

        op, addr, sl = instr.as_order()
        wide = (sl == "L")

        if op == "T":
            # TnS: m[n]=A; ABC=0
            # TnL: w[n]=AB; ABC=0
            a = self.get_accumulator(wide)
            self.set_memory(addr, a, wide)
            self.clear_accumulator()
        elif op == "H":
            # HnS: R += m[n]
            # HnL: RS += w[n]
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            r = m
            self.set_multiplier(r, wide)

        elif op == "E":
            # if A >= 0 goto n
            a = self.get_accumulator()
            if not a.is_negative():  # A >= 0
                self.sequence_control = addr - 1
        elif op == "G":
            # if A < 0 goto n
            a = self.get_accumulator()
            if a.is_negative():  # A < 0
                self.sequence_control = addr - 1

        elif op == "I":
            #  Place the next paper tape character
            #  in the *least* significant 5 bits of m[n].
            c = self.cards[self.next_char]
            self.next_char += 1
            v = io.ascii_to_edsac(c)
            self.set_memory(addr, Value.new_from_number(v))
            if DEBUG_IO:
                print "read", c, v

        elif op == "A":
            # AnS: A += m[n]
            # AnL: AB += w[n]
            m = self.get_memory(addr, wide)
            r = self.get_accumulator(wide)
            r = r + m
            self.set_accumulator(r, wide)
        elif op == "S":
            m = self.get_memory(addr, wide)
            r = self.get_accumulator(wide)
            r = r - m
            self.set_accumulator(r, wide)

        elif op == "V":
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            v = m.multiply(r)
            if wide:
                a = self.accumulator
            else:
                a = self.get_accumulator(wide=True)
            a.set(a + v)

        elif op == "N":
            m = self.get_memory(addr, wide)
            r = self.get_multiplier(wide)
            v = m.as_integer() * r.as_integer()
            v = m.multiply(r)
            if wide:
                a = self.accumulator
            else:
                a = self.get_accumulator(wide=True)
            a.set(a - v)

        elif op == "R":
            # Shift right
            num_shift = _calc_num_shift(instr)
            v = self.accumulator.as_integer()
            v = v >> num_shift
            self.accumulator.set_from_number(v)

        elif op == "L":
            # Shift left
            num_shift = _calc_num_shift(instr)
            v = self.accumulator.as_unsigned()
            v = v << num_shift
            self.accumulator.set_from_number(v)

        elif op == "U":
            # UnS: m[n]=A
            # UnL: w[n]=AB
            self.set_memory(addr, self.get_accumulator(wide), wide)

        elif op == "C":
            raise NotImplementedError
        elif op == "Y":
            raise NotImplementedError

        elif op == "O":
            # output
            if DEBUG_IO:
                code = self.get_memory(addr).as_charcode()
                print "output %s %s %s" % (io.edsac_to_letter(code),
                                           io.edsac_to_figure(code), code)
            else:
                sys.stdout.write(
                    self.output(self.get_memory(addr).as_charcode()))

        elif op == "X":
            pass  # no operation
        elif op == "F":
            raise NotImplementedError("Verify the last character"
                                      "output. What?")
        elif op == "Z":
            # finish
            return True
        else:
            raise AssertionError("Malformed Instruction:", instr.as_order())

        self.sequence_control += 1
        return False  # not finished