DASM
DCPU.pm
Go to the documentation of this file.
00001 #!/usr/bin/perl -w
00002 ##
00003 # DCPU-16 definitions.
00004 #
00005 # Taken from the specification at http://0x10c.com/doc/dcpu-16.txt
00006 #
00007 # We provide package variables for all of the definitions we use in the
00008 # assembler kit.
00009 #
00010 # @file
00011 # @author Justin Fletcher
00012 #
00013 
00014 package DCPU;
00015 
00016 ## Mapping from register name to instruction value
00017 our %RegisterMap = (
00018         'A' => 0,
00019         'B' => 1,
00020         'C' => 2,
00021         'X' => 3, 
00022         'Y' => 4, 
00023         'Z' => 5, 
00024         'I' => 6, 
00025         'J' => 7
00026     );
00027 
00028 ## Inverse mapping of instruction value to register
00029 our %InvRegisterMap = map { $RegisterMap{$_} => $_ } keys %RegisterMap;
00030 
00031 ## Basic opcode mapping
00032 our %BasicOps = (
00033         'EXT'  => 0, # Extended opcode
00034         'SET'  => 1,
00035         'ADD'  => 2,
00036         'SUB'  => 3,
00037         'MUL'  => 4,
00038         'DIV'  => 5,
00039         'MOD'  => 6,
00040         'SHL'  => 7,
00041         'SHR'  => 8,
00042         'AND'  => 9,
00043         'BOR'  => 10,
00044         'XOR'  => 11,
00045         'IFE'  => 12,
00046         'IFN'  => 13,
00047         'IFG'  => 14,
00048         'IFB'  => 15,
00049     );
00050 
00051 ## Inverse basic opcode mapping
00052 our %InvBasicOps = map { $BasicOps{$_} => $_ } keys %BasicOps;
00053 
00054 ## Extended opcode, mapped into opcode 0
00055 our %ExtendedOps = (
00056         # ExtOpcode 0 is reserved
00057         'JSR'  => 1,
00058         # ExtOpcode 2-15 is reserved
00059     );
00060 
00061 ## Inverse basic opcode mapping
00062 our %InvExtendedOps = map { $ExtendedOps{$_} => $_ } keys %ExtendedOps;
00063 
00064 
00065 1;