Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CPU now loads object code from file

  • Loading branch information...
commit 3ee943d89e71f3843a53a78a6fef1f516c3dde62 1 parent 8c5b7cb
@jtauber authored
Showing with 17 additions and 9 deletions.
  1. +17 −9 dcpu16.py
View
26 dcpu16.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python
+import sys
+
+
class Cell:
"""
a cell enables us to pass around a reference to a register or memory location rather than the value
@@ -179,12 +182,17 @@ def dump_stack(self):
if __name__ == "__main__":
- example = [
- 0x7c01, 0x0030, 0x7de1, 0x1000, 0x0020, 0x7803, 0x1000, 0xc00d,
- 0x7dc1, 0x001a, 0xa861, 0x7c01, 0x2000, 0x2161, 0x2000, 0x8463,
- 0x806d, 0x7dc1, 0x000d, 0x9031, 0x7c10, 0x0018, 0x7dc1, 0x001a,
- 0x9037, 0x61c1, 0x7dc1, 0x001a, 0x0000, 0x0000, 0x0000, 0x0000,
- ]
-
- dcpu16 = DCPU16(example)
- dcpu16.run(debug=True)
+ if len(sys.argv) == 2:
+ program = []
+ f = open(sys.argv[1])
+ while True:
+ hi = f.read(1)
+ if not hi:
+ break
+ lo = f.read(1)
+ program.append((ord(hi) << 8) + ord(lo))
+
+ dcpu16 = DCPU16(program)
+ dcpu16.run(debug=True)
+ else:
+ print "usage: ./dcup16.py <object-file>"
Please sign in to comment.
Something went wrong with that request. Please try again.