Commits

Kevin Veroneau  committed 61bf333

Major update to CPU simulator, existing bytecode will need to be recompiled to use this new core.
Work has begun to rework the op-codes to be more powerful and similar to standard assembly.

Removed op-codes:
ax
bx
cx
dx
cx++
cx--
addcx
subcx

New op-codes:
mov
inc
dec
add
sub
mul
div
swp

Updated op-codes:
push
pop
use

The Coder class has been completely remade using the standard cmd.Cmd module.

  • Participants
  • Parent commits 801e91d

Comments (0)

Files changed (6)

File CursesHook.py

+"""
+This python module includes a CPU Hook that enables controlled apps to use the ncurses library.
+This is an example of how you might extend the CPU simulator to access the outside world.
+"""
+
+from cpu import BaseCPUHook
+import curses
+
+class CursesHook(BaseCPUHook):
+    opcode = 67
+    opname = 'cur'
+    stdscr = None
+    def cleanup(self):
+        if self.stdscr is None:
+            return
+        self.stdscr.keypad(0)
+        curses.echo()
+        curses.nocbreak()
+        curses.endwin()
+        self.stdscr = None
+    def hook_1(self):
+        if self.stdscr is None:
+            self.stdscr = curses.initscr()
+            curses.noecho()
+            curses.cbreak()
+            self.stdscr.keypad(1)
+            try:
+                curses.start_color()
+            except:
+                pass
+            self.wins = []
+            self.style = curses.A_NORMAL
+    def hook_2(self):
+        if self.stdscr is None:
+            return
+        self.cpu.mem.push()
+        self.cpu.mem.ptr = self.cpu.ax.b
+        self.wins.append(curses.newwin(self.cpu.mem.read().b, self.cpu.mem.read().b, self.cpu.mem.read().b, self.cpu.mem.read().b))
+        self.cpu.ax.value = len(self.wins)-1
+        self.cpu.mem.pop()
+    def hook_3(self):
+        if self.stdscr is None:
+            return
+        self.cpu.mem.push()
+        self.cpu.mem.ptr = self.cpu.bx.b
+        text = self.cpu.mem.readstring()
+        self.cpu.mem.pop()
+        self.wins[self.cpu.ax.b].addstr(self.cpu.cx.b, self.cpu.dx.b, text, self.style)
+    def hook_4(self):
+        if self.stdscr is None:
+            return
+        self.cpu.cx.value = self.wins[self.cpu.ax.b].getch()
+    def hook_10(self):
+        if self.stdscr is None:
+            return
+        self.wins[self.cpu.ax.b].idlok(self.cpu.bx.b)
+    def hook_11(self):
+        if self.stdscr is None:
+            return
+        self.cpu.mem.push()
+        self.cpu.mem.ptr = self.cpu.bx.b
+        border = self.cpu.mem.read(8)
+        self.wins[self.cpu.ax.b].border(*list(border))
+        self.cpu.mem.pop()
+    def hook_255(self):
+        self.cleanup()
 from cStringIO import StringIO
 import sys
 import zlib
+from cmd import Cmd
+import shlex
+import os
 try:
     import termios
 except ImportError:
             return True
         else:
             return False
+    def __len__(self):
+        return len(self.c)
     @property
     def b(self):
         """Get the byte value."""
         self.mem.write('\x00' * self.size)
         self.mem.seek(0)
         self._ptr = 0
+        self._ptr_stack = []
     def __len__(self):
         return self.size
     def __check_key(self, key):
         if value < 0 or value > self.size-1:
             raise ValueError
         self.mem.seek(value)
+    def push(self):
+        self._ptr_stack.append(self.ptr)
+    def pop(self):
+        self.ptr = self._ptr_stack.pop()
     def read(self, num=1, force8=False):
         if self.eom:
             print "Memory error: %d" % self.ptr
     def read16(self):
         if self.eom:
             print "Memory error: %d" % self.ptr
-        return Unit16(self.mem.read(2))
+        if self.size > 256:
+            return Unit16(self.mem.read(2))
+        return Unit(self.mem.read(1))
     def write(self, value):
         if isinstance(value, Unit):
             self.mem.write(value.c)
             self.mem.write(value)
         else:
             raise ValueError
+    def write16(self, value):
+        if self.size > 256:
+            self.mem.write(Unit16(value).c)
+        else:
+            self.mem.write(chr(value))
     def readstring(self, term='\x00'):
         s = ''
         while True:
             self.mem = open(filename, 'w+b')
             self.clear()
 
-class Coder(object):
-    bc_map = {
-        'int': 1,
-        'ax': 2,
-        'bx': 3,
-        'cx': 4,
-        'dx': 5,
+class Coder(Cmd):
+    bc16_map = {
         'jmp': 6,
-        'push': 7,
-        'pop': 8,
         'call': 9,
-        'cx++': 10,
-        'cx--': 11,
-        'addcx': 12,
-        'subcx': 13,
-        'use': 14,
         'if=': 15,
         'if!': 16,
-        'six': 17,
     }
-    def __init__(self, cpu, compress=False):
+    bc_map = {
+        'int': [1,0],
+        'push': [7,0],
+        'pop': [8,0],
+        'inc': [10,3],
+        'dec': [11,3],
+        'use': [14,3],
+    }
+    bc2_map = {
+        'mov': 2,
+        'add': 12,
+        'sub': 13,
+        'swp': 17,
+        'mul': 18,
+        'div': 19,
+    }
+    var_map = {
+        'ptr': 0,
+        'ax': 1,
+        'bx': 2,
+        'cx': 3,
+        'dx': 4,
+    }
+    prompt = '0 '
+    def configure(self, cpu):
         if not isinstance(cpu, CPU):
             raise TypeError
         self.cpu = cpu
-        self.compress = compress
         for hook in self.cpu.cpu_hooks:
-            self.bc_map.update({self.cpu.cpu_hooks[hook].opname: hook})
-    def parse(self, c):
+            self.bc_map.update({self.cpu.cpu_hooks[hook].opname: [hook,0]})
+    def unknown_command(self, line):
+        self.stdout.write('*** Unknown syntax: %s\n'%line)
+    def emptyline(self):
+        pass
+    def postcmd(self, stop, line):
+        self.prompt = '%s ' % self.cpu.mem.ptr
+        return stop
+    def get_int(self, arg):
         try:
-            sp = c.index(' ')
-            return (c[0:sp], c[sp+1:])
-        except ValueError:
-            return (c, '')
-    def __call__(self):
-        while True:
-            op, arg = self.parse(raw_input("%d " % self.cpu.mem.ptr))
-            if op in self.bc_map:
-                self.cpu.mem.write(self.bc_map[op])
-                if arg != '':
-                    self.cpu.mem.write(int(arg))
-            elif op == 'boot':
-                if arg != '':
-                    self.cpu.run(int(arg))
-                else:
-                    self.cpu.run(self.cpu.mem.ptr)
-            elif op == 'string':
-                for c in arg:
-                    self.cpu.mem.write(2)
-                    self.cpu.mem.write(ord(c))
-                    self.cpu.mem.write(1)
-                    self.cpu.mem.write(3)
-            elif op == 'ptr':
-                if arg != '':
-                    self.cpu.mem.ptr = int(arg)
-                else:
-                    print self.cpu.mem.ptr
-            elif op == 'dump':
-                if arg != '':
-                    ptr = int(arg)
-                else:
-                    ptr = self.cpu.mem.ptr
-                print self.cpu.mem[ptr].b
-            elif op == 'dump+':
-                print self.cpu.mem.read().b
-            elif op == 'dump16+':
-                print self.cpu.mem.read16().b
-            elif op == 'savebin':
-                if arg != '':
-                    self.cpu.savebin(arg, self.compress)
-            elif op == 'loadbin':
-                if arg != '':
-                    self.cpu.loadbin(arg, self.compress)
-            elif op == 'clear':
-                self.cpu.mem.clear()
-            elif op == 'data':
-                for c in arg:
-                    self.cpu.mem.write(ord(c))
-                self.cpu.mem.write(0)
-            elif op == 'set':
-                if arg != '':
-                    self.cpu.mem.write(int(arg))
-            elif op == 'bp':
-                if arg != '':
-                    self.cpu.bp = int(arg)
-                else:
-                    self.cpu.bp = self.cpu.mem.ptr
-            elif op == 'cbp':
-                del self.cpu.bp
-            elif op == '.' or self.cpu.mem.eom:
-                break
-            elif op == 'state':
-                print 'CPU State info:'
-                print 'AX=%s\nBX=%s\nCX=%s\nDX=%s' % (self.cpu.ax.b, self.cpu.bx.b, self.cpu.cx.b, self.cpu.dx.b)
-                print '16-bit mode enable: %s' % ('Yes' if self.cpu.mem.sixteen else 'No')
-        self.cpu.savebin('dump', self.compress)
+            return int(arg)
+        except:
+            pass
+        try:
+            return self.var_map[arg]
+        except:
+            return 0
+    def default(self, line):
+        if line == '.':
+            return True
+        s = shlex.split(line)
+        op, arg = s[0], ''
+        if len(s) > 1:
+            try:
+                ptr = int(s[0])
+                self.cpu.mem.ptr = ptr
+                op = s[1]
+            except:
+                arg = s[1]
+        if len(s) in [3,4]:
+            try:
+                ptr, op, arg = int(s[0]), s[1], s[2]
+                self.cpu.mem.ptr = ptr
+            except:
+                pass
+        if op in self.bc16_map:
+            self.cpu.mem.write(self.bc16_map[op])
+            if arg != '':
+                self.cpu.mem.write16(int(arg))
+        elif op in self.bc_map:
+            self.cpu.mem.write(self.bc_map[op][0])
+            if arg == '':
+                self.cpu.mem.write(int(self.bc_map[op][1]))
+            else:
+                self.cpu.mem.write(self.get_int(arg))
+        elif op in self.bc2_map:
+            self.cpu.mem.write(self.bc2_map[op])
+            try:
+                a1,a2 = arg.split(',')
+            except:
+                self.cpu.mem.ptr -= 1
+                self.unknown_command(line)
+                return
+            if a1 in self.var_map:
+                a2 = self.get_int(a2)
+                try:
+                    self.cpu.mem.write(self.var_map[a1])
+                    if op == 'swp':
+                        self.cpu.mem.write(int(a2))
+                    else:
+                        self.cpu.mem.write16(int(a2))
+                except:
+                    self.cpu.mem.ptr -= 1
+                    self.unknown_command(line)
+                    return
+            else:
+                self.cpu.mem.ptr -= 1
+                self.stdout.write(' ** Invalid register: %s\n' % a1)
+                return
+        else:
+            self.unknown_command(line)
+    def do_boot(self, args):
+        """ Executes the code currently in memory at an optional memory pointer location. """
+        if args != '':
+            self.cpu.run(int(args))
+        else:
+            self.cpu.run(self.cpu.mem.ptr)
+    def do_string(self, args):
+        """ A macro to write a string to the screen 1 character at a time. """
+        s = shlex.split(args)
+        for c in s[0]:
+            self.cpu.mem.write(2)
+            self.cpu.mem.write(1)
+            self.cpu.mem.write(ord(c))
+            self.cpu.mem.write(1)
+            self.cpu.mem.write(3)
+    def do_ptr(self, args):
+        """ Sets or returns the current pointer location in memory. """
+        if args != '':
+            self.cpu.mem.ptr = int(args)
+        else:
+            print self.cpu.mem.ptr
+    def do_dump(self, args):
+        """ Dumps the byte at the current memory location. """
+        if args != '':
+            ptr = int(args)
+        else:
+            ptr = self.cpu.mem.ptr
+        self.stdout.write("%s" % self.cpu.mem[ptr].b)
+        if self.cpu.mem[ptr].b > 64:
+            self.stdout.write(" / %s" % self.cpu.mem[ptr].c)
+        self.stdout.write('\n')
+    def do_dump16(self, args):
+        """ Dumps a 16-bit integer from the current memory location. """
+        if args != '':
+            optr = self.cpu.mem.ptr
+            self.cpu.mem.ptr = int(args)
+        self.stdout.write("%s\n" % self.cpu.mem.read16().b)
+        if args != '':
+            self.cpu.mem.ptr = optr
+    def do_savebin(self, args):
+        """ Saves the current binary image in memory to disc. """
+        s = shlex.split(args)
+        if len(s) > 0:
+            self.cpu.savebin(s[0])
+    def do_loadbin(self, args):
+        """ Loads a binary image from disc into memory. """
+        s = shlex.split(args)
+        if len(s) > 0:
+            if self.cpu.loadbin(s[0]) == False:
+                self.stdout.write('The binary is too large to fit in memory.\n')
+    def do_clear(self, args):
+        """ Clears the current data in memory. """
+        self.cpu.mem.clear()
+        readline.clear_history()
+    def do_data(self, args):
+        """ Stores a zero-terminated string to the current memory address. """
+        s = shlex.split(args)
+        if len(s) > 0:
+            for c in s[0]:
+                self.cpu.mem.write(ord(c))
+            self.cpu.mem.write(0)
+    def do_set(self, args):
+        """ Stores a raw byte at the current memory location. """
+        if args != '':
+            self.cpu.mem.write(int(args))
+    def do_bp(self, args):
+        """ Sets a breakpoint at the current memory location. """
+        if args != '':
+            self.cpu.bp = int(args)
+        else:
+            self.cpu.bp = self.cpu.mem.ptr
+    def do_cbp(self, args):
+        """ Clears a currently set breakpoint. """
+        del self.cpu.bp
+    def do_source(self, args):
+        """ Loads in a source file. """
+        s = shlex.split(args)
+        if len(s) != 1:
+            self.stdout.write('Please specify a filename to read in.\n')
+            return False
+        try:
+            script = open(s[0], 'r').readlines()
+            for line in script:
+                self.cmdqueue.append(line)
+        except:
+            self.stdout.write('Error loading source.\n')
+    def do_memory(self, args):
+        """ Changes or views the current memory size. """
+        s = shlex.split(args)
+        if len(s) != 1:
+            self.stdout.write('Current memory size: %s\n' % self.cpu.mem.size)
+            return False
+        try:
+            self.cpu.mem = Memory(int(s[0]))
+        except:
+            self.stdout.write('Please specify a size in bytes.\n')
+    def do_registers(self, args):
+        """ Prints the current state of the CPU registers. """
+        self.stdout.write('AX=%s, BX=%s, CX=%s, DX=%s\n' % (self.cpu.ax.b, self.cpu.bx.b, self.cpu.cx.b, self.cpu.dx.b))
+    def do_memcopy(self, args):
+        """ Performs a memory copy operation. """
+        s = shlex.split(args)
+        if len(s) != 3:
+            self.stdout.write('Please specify the following: src, dest, size\n')
+            return False
+        try:
+            self.cpu.mem.memcopy(int(s[0]), int(s[1]), int(s[2]))
+        except:
+            self.stdout.write('There was an error during the copy operation.\n')
+    def do_memclear(self, args):
+        """ Clear a specific segment of memory. """
+        s = shlex.split(args)
+        if len(s) != 2:
+            self.stdout.write('Please specify the following: src, size\n')
+            return False
+        try:
+            self.cpu.mem.memclear(int(s[0]), int(s[1]))
+        except:
+            self.stdout.write('There was an error during the memory clear operation.\n')
+    def do_memmove(self, args):
+        """ Moves a segment of memory to a new location. """
+        s = shlex.split(args)
+        if len(s) != 3:
+            self.stdout.write('Please specify the following: src, dest, size\n')
+            return False
+        optr = self.cpu.mem.ptr
+        try:
+            src = int(s[0])
+            dest = int(s[1])
+            size = int(s[2])
+        except:
+            self.stdout.write('Please provide numeric parameters only.\n')
+            return False
+        try:
+            self.cpu.mem.ptr = src
+            buf = self.cpu.mem.read(size)
+        except:
+            self.stdout.write('There was an error during the read operation.\n')
+            self.cpu.mem.ptr = optr
+            return False
+        try:
+            self.cpu.mem.memclear(src, size)
+        except:
+            self.stdout.write('There was an error during the clear operation.\n')
+            self.cpu.mem.ptr = src
+            self.cpu.mem.write(buf)
+            self.cpu.mem.ptr = optr
+            return False
+        try:
+            self.cpu.mem.ptr = dest
+            old = self.cpu.mem.read(size)
+            self.cpu.mem.ptr = dest
+            self.cpu.mem.write(buf)
+        except:
+            self.stdout.write('There was an error during the write operation.\n')
+            self.cpu.mem.ptr = dest
+            self.cpu.mem.write(old)
+            self.cpu.mem.ptr = src
+            self.cpu.mem.write(buf)
+            self.cpu.mem.ptr = optr
+    def do_stepping(self, args):
+        """ Turn on or off register stepping for each command run. """
+        if args == 'off':
+            del self.cpu.stepping
+        else:
+            self.cpu.stepping = True
+    def do_savecode(self, args):
+        """ Save your history of typed commands. """
+        s = shlex.split(args)
+        if len(s) == 1:
+            readline.write_history_file(s[0])
+            os.chmod(s[0], 33188)
 
 class BaseCPUHook(object):
     def __init__(self, cpu):
         except AttributeError:
             raise InvalidInterrupt("HOOK %d is not defined." % i)
         func()
+    def cleanup(self):
+        pass
 
 class HelloWorldHook(BaseCPUHook):
     opcode = 60
         cli()
 
 class CPUCore(object):
-    ax = Unit()
-    bx = Unit()
-    cx = Unit()
-    dx = Unit()
+    ax = Unit16()
+    bx = Unit16()
+    cx = Unit16()
+    dx = Unit16()
+    var_map = {
+        0: 'ptr',
+        1: 'ax',
+        2: 'bx',
+        3: 'cx',
+        4: 'dx',
+    }
     def add_cpu_hook(self, klass):
         hook = klass(self)
         self.cpu_hooks.update({hook.opcode: hook})
+    def hook_cleanup(self):
+        for hook in self.cpu_hooks:
+            self.cpu_hooks[hook].cleanup()
     def dump(self):
         self.mem.ptr = 0
         for i in range(0, (len(self.mem)/2)-1):
     def run(self, ptr=0):
         self.mem.ptr = ptr
         exitcode = 0
-        sjmp = ptr
+        stack = []
         if termios:
             attr = termios.tcgetattr(sys.stdin)
             oldattr = attr[3]
         while True:
             if 'bp' in self.__dict__ and self.bp == self.mem.ptr: break
             if self.mem.eom: break
-            op = self.mem.read(force8=True).b
+            op = self.mem.read().b
+            if 'stepping' in self.__dict__:
+                print "PTR: %s, OP: %s, AX: %s, BX: %s, CX: %s, DX: %s" % (self.mem.ptr, op, self.ax.b, self.bx.b, self.cx.b, self.dx.b)
             if op == 1:
-                rt = self.do_int(self.mem.read(force8=True).b)
+                rt = self.do_int(self.mem.read().b)
                 if rt == 1:
                     exitcode = 1
                     break
             elif op == 2:
-                self.ax = self.mem.read()
-            elif op == 3:
-                self.bx = self.mem.read()
-            elif op == 4:
-                self.cx = self.mem.read()
-            elif op == 5:
-                self.dx = self.mem.read()
+                v = self.mem.read().b
+                reg = self.mem.read16()
+                if v > 0:
+                    getattr(self, self.var_map[v]).value = reg.b
+                else:
+                    self.mem.ptr = reg.b
             elif op == 6:
-                jmp = self.mem.read()
+                jmp = self.mem.read16()
                 self.mem.ptr = jmp.b
             elif op == 7:
-                sjmp = self.mem.ptr
+                v = self.mem.read().b
+                if v > 0:
+                    stack.append(getattr(self, self.var_map[v]).b)
+                else:
+                    stack.append(self.mem.ptr)
             elif op == 8:
-                self.mem.ptr = sjmp
+                v = self.mem.read().b
+                if v > 0:
+                    getattr(self, self.var_map[v]).value = stack.pop()
+                else:
+                    self.mem.ptr = stack.pop()
             elif op == 9:
-                sjmp = self.mem.ptr + 1
-                jmp = self.mem.read()
+                stack.append(self.mem.ptr + 1)
+                jmp = self.mem.read16()
                 self.mem.ptr = jmp.b
             elif op == 10:
-                self.cx += 1
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg += 1
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
             elif op == 11:
-                self.cx -= 1
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg -= 1
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
             elif op == 12:
-                self.cx += self.mem.read()
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg += self.mem.read16().b
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
             elif op == 13:
-                self.cx -= self.mem.read()
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg -= self.mem.read16().b
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
             elif op == 14:
-                self.cx = self.mem[self.cx.b]
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn)
+                reg.value = self.mem[reg.b].b
+                if v > 0:
+                    getattr(self, vn).value = reg.b
+                else:
+                    self.mem.ptr = reg.b
             elif op == 15:
-                if self.cx == self.mem.read():
+                if self.cx == self.mem.read16():
                     self.mem.ptr = self.dx.b
             elif op == 16:
-                if self.cx != self.mem.read():
+                if self.cx != self.mem.read16():
                     self.mem.ptr = self.dx.b
             elif op == 17:
-                self.mem.sixteen = False if self.mem.sixteen else True
+                v1, v2 = self.mem.read().b, self.mem.read().b
+                if v1 > 0:
+                    reg1 = getattr(self, self.var_map[v1]).b
+                else:
+                    reg1 = self.mem.ptr
+                if v2 > 0:
+                    reg2 = getattr(self, self.var_map[v2]).b
+                else:
+                    reg2 = self.mem.ptr
+                old = reg1
+                reg1.value = reg2
+                reg2.value = old
+            elif op == 18:
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg *= self.mem.read16().b
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
+            elif op == 19:
+                v = self.mem.read().b
+                vn = self.var_map[v]
+                reg = getattr(self, vn).b
+                reg /= self.mem.read16().b
+                if v > 0:
+                    getattr(self, vn).value = reg
+                else:
+                    self.mem.ptr = reg
             elif self.cpu_hooks.has_key(op):
                 self.cpu_hooks[op](self.mem.read().b)
         if termios:
             attr[3] = oldattr
             termios.tcsetattr(sys.stdin, termios.TCSANOW, attr)
+        self.hook_cleanup()
 
 class CPU(CPUCore, CPUInterrupts):
     cpu_memory = 64
     def loadbin(self, filename, compressed=False):
         self.mem.clear()
         if not compressed:
-            self.mem.write(open(filename, 'rb').read())
+            bindata = open(filename, 'rb').read()
         else:
-            self.mem.write(zlib.decompress(open(filename, 'rb').read()))
+            bindata = zlib.decompress(open(filename, 'rb').read())
+        self.mem = Memory(len(bindata))
+        self.mem.write(bindata)
         self.mem.ptr = 0
     def savebin(self, filename, compress=False):
         if not compress:
 
 if __name__ == '__main__':
     import readline
-    c = CPU('hello.bin', True)
+    c = CPU()
     c.add_cpu_hook(BinLoaderHook)
-    cli = Coder(c)
-    cli()
+    cli = Coder()
+    cli.configure(c)
+    cli.cmdloop()

File hello.bin

Binary file modified.
 This is the source code for hello.bin, which you can view in a hex editor:
 
 ---------
+memory 64
 jmp 30
-data Hello Simple CPU Simulator!
-ax 2
+data "Hello Simple CPU Simulator!"
+mov ax,2
 int 10
+mov ax,10
+int 3
 int 1
 savebin hello.bin
 boot 0

File introduction.txt

   Example to load a binary file and immediately jump into the debugger with it:
     import readline
     c = CPU('myapp')
-    cli = Coder(c)
-    cli()
+    cli = Coder()
+    cli.configure(c)
+    cli.cmdloop()
   A CPU instance needs to be passed into the Coder, or it will not work.  You can also pass an empty CPU instance as well, to start a fresh new application.
 
 Storage Klass(sub-class of Memory):
   It provides the facility to add and subtract Units or ints, and conditional matching.
   It controls the attribute setting to prevent values outside the 255 range, which this CPU simulator does not yet support.
 
+Unit16 Klass:
+  This class is a subclass of Unit klass above, but is able to store 16-bit integers in 2-bytes.
+
 Please read the other included text files for more information on how to use this CPU simulator toolkit.

File op-codes.txt

 INT:
   byte-code: 1
   Next byte should be the interrupt to call.
-  See the sample-interrupts.txt for list of possible interrupts.
-AX:
+  See the interrupts.txt for list of possible interrupts.
+MOV:
   byte-code: 2
-  AX register is set to the next read byte in memory.
-BX:
-  byte-code: 3
-  BX register is set to the next read byte in memory.
-CX:
-  byte-code: 4
-  CX register is set to the next read byte in memory.
-DX:
-  byte-code: 5
-  DX register is set to the next read byte in memory.
+  Sets the register specified to an integer.
+  eg: mov ax,5
 JMP:
   byte-code: 6
   Set CPU Memory pointer to the next read byte in memory.
 PUSH:
   byte-code: 7
-  Store the current CPU Memory pointer for a later use.
+  Pushes a register into the stack.
+  eg: push ptr
+  eg: push ax
 POP:
   byte-code: 8
-  Restore the previously stored CPU Memory pointer.
+  Restore the previously pushed register.
+  eg: pop ptr
+  eg: pop cx
 CALL:
   byte-code: 9
   PUSHes the next to execute CPU Memory pointer, then performs a JMP using the next read byte.
-CX++:
+INC:
   byte-code: 10
-  Increments CX by 1.
-CX--:
+  Increments a register by 1.
+  eg: inc cx
+DEC:
   byte-code: 11
-  Decreases CX by 1.
-ADDCX:
+  Decreases a register by 1.
+  eg: dec bx
+ADD:
   byte-code: 12
-  Increments CX by the next read byte.
-SUBCX:
+  Increments a register by any amount.
+  eg: add cx,5
+SUB:
   byte-code: 13
-  Decreases CX by the next read byte.
+  Decreases a register by any amount.
+  eg: sub bx,2
+MUL:
+  byte-code: 18
+  Multiplies a register with any amount.
+  eg: mul dx,2
+DIV:
+  byte-code: 19
+  Divides a register with any amount.
+  eg: div ax,4
 USE:
   byte-code: 14
-  Sets CX to the byte stored at CPU Memory pointer stored in CX...
-  I know it sounds confusing, and it sort of is.  It's used with the IFs mainly.
+  Sets a register to the address currently in the register.
+  eg: use cx
 IF=:
   byte-code: 15
   If CX equals the value in the next read byte, then set the CPU Memory pointer to DX.
 IF!:
   byte-code: 16
   If CX does not equals the value in the next read byte, then set the CPU Memory pointer to DX.
-SIX:
+SWP:
   byte-code: 17
-  Enable 16-bit memory locations(still under development use at own risk!)
+  Swaps bytes in AX and BX.