@@ -0,0 +1,852 @@
+#!/usr/bin/env python%0A%22%22%22%0ASynacor challenge for OSCON 2012.%0A%0AArchitecture description in file arch-spec.%0A%22%22%22%0Aimport struct%0Aimport sys%0A%0A%0A# Memory with 15-bit address space storing 16-bit numbers.%0A# %7Baddress: number%7D%0AMEM = %5B%5D%0A# 8 (16-bit) Registers%0AREGS = %5Bi for i in xrange(8)%5D%0A# Unbounded stack%0ASTACK = %5B%5D%0A%0A%0Adef run():%0A    %22%22%22Run application from memory.%22%22%22%0A    offset = 0%0A    while True:%0A        op = MEM%5Boffset%5D%0A%0A%0Adef main():%0A    %22%22%22Run this as ./vm.py %3Cinputfile%3E.%22%22%22%0A    try:%0A        infile = sys.argv%5B1%5D%0A    except IndexError:%0A        sys.exit(main.__doc__)%0A%0A    # Read input file into memory.%0A    with open(infile, 'rb') as f:%0A        # Read 16 bits at a time.%0A        chunk = f.read(2)%0A        while chunk != '':%0A            MEM.append(struct.unpack('%3CH', chunk)%5B0%5D)%0A            chunk = f.read(2)%0A%0A%0A# Run it%0Aif __name__ == '__main__':%0A    main()

Read input file into "memory"