All pastes #927295 Raw Edit

Mine

public python v1 · immutable
·published 2008-03-04 04:43 UTC
rendered paste body
LDX = 0x01 #Load XLDY = 0x02 #Load YIOX = 0x03 #IO, 0x01 for output, 0x02 for inputHLT = 0x04 #Halt the processorclass cpuEmulator(object):    def __init__(self, data=[]):        self.memory = data        self.p = 0        self.regX = self.regY = 0            def _ldx(self):        self.regX = self.memory[self.p+1]        self.p += 2    def _ldy(self):        self.regY = self.memory[self.p+1]        self.p += 2    def _iox(self):        if self.regX == 0x01:            print ''.join(self.memory[self.regY:self.memory.index('\0')])        self.p += 1    def run(self):        running = True        while running:            if self.memory[self.p] == LDX:  self._ldx()            elif self.memory[self.p] == LDY:  self._ldy()            elif self.memory[self.p] == IOX:  self._iox()            elif self.memory[self.p] == HLT:                print "System halted!"                running = FalseCPU = cpuEmulator([LDX,0x01,LDY,0x06,IOX,HLT,'J','u','s','t',' ','a',' ','t','e','s','t','!','\n','\0'])CPU.run()