1 | open BitVectors;; |
---|
2 | |
---|
3 | type ('a,'b) union2 = [ `U1 of 'a | `U2 of 'b ] |
---|
4 | type ('a,'b,'c) union3 = [ `U1 of 'a | `U2 of 'b | `U3 of 'c ] |
---|
5 | type ('a,'b,'c,'d,'e,'f) union6 = [ `U1 of 'a | `U2 of 'b | `U3 of 'c | `U4 of 'd | `U5 of 'e | `U6 of 'f ] |
---|
6 | |
---|
7 | type direct = [ `DIRECT of byte ] |
---|
8 | type indirect = [ `INDIRECT of bit ] |
---|
9 | type ext_indirect = [ `EXT_INDIRECT of bit ] |
---|
10 | type reg = [ `REG of bit * bit * bit ] |
---|
11 | type acc = [ `A ] |
---|
12 | type b = [ `B ] |
---|
13 | type dptr = [ `DPTR ] |
---|
14 | type data = [ `DATA of byte ] |
---|
15 | type data16 = [ `DATA16 of word ] |
---|
16 | type acc_dptr = [ `A_DPTR ] |
---|
17 | type acc_pc = [ `A_PC ] |
---|
18 | type ext_indirect_dptr = [ `EXT_IND_DPTR ] |
---|
19 | type indirect_dptr = [ `IND_DPTR ] |
---|
20 | type carry = [ `C ] |
---|
21 | type bit = [ `BIT of byte ] |
---|
22 | type nbit = [ `NBIT of byte ] |
---|
23 | type rel = [ `REL of byte ] |
---|
24 | type addr11 = [ `ADDR11 of word11 ] |
---|
25 | type addr16 = [ `ADDR16 of word ] |
---|
26 | |
---|
27 | type instruction = |
---|
28 | (* arithmetic operations *) |
---|
29 | [ `ADD of acc * [ reg | direct | indirect | data ] |
---|
30 | | `ADDC of acc * [ reg | direct | indirect | data ] |
---|
31 | | `SUBB of acc * [ reg | direct | indirect | data ] |
---|
32 | | `INC of [ acc | reg | direct | indirect | dptr ] |
---|
33 | | `DEC of [ acc | reg | direct | indirect ] |
---|
34 | | `MUL of acc * b |
---|
35 | | `DIV of acc * b |
---|
36 | | `DA of acc |
---|
37 | |
---|
38 | (* logical operations *) |
---|
39 | | `ANL of |
---|
40 | (acc * [ reg | direct | indirect | data ], |
---|
41 | direct * [ acc | data ], |
---|
42 | carry * [ bit | nbit]) union3 |
---|
43 | | `ORL of |
---|
44 | (acc * [ reg | data | direct | indirect ], |
---|
45 | direct * [ acc | data ], |
---|
46 | carry * [ bit | nbit]) union3 |
---|
47 | | `XRL of |
---|
48 | (acc * [ data | reg | direct | indirect ], |
---|
49 | direct * [ acc | data ]) union2 |
---|
50 | | `CLR of [ acc | carry | bit ] |
---|
51 | | `CPL of [ acc | carry | bit ] |
---|
52 | | `RL of acc |
---|
53 | | `RLC of acc |
---|
54 | | `RR of acc |
---|
55 | | `RRC of acc |
---|
56 | | `SWAP of acc |
---|
57 | |
---|
58 | (* data transfer *) |
---|
59 | | `MOV of |
---|
60 | (acc * [ reg | direct | indirect | data ], |
---|
61 | [ reg | indirect ] * [ acc | direct | data ], |
---|
62 | direct * [ acc | reg | direct | indirect | data ], |
---|
63 | dptr * data16, |
---|
64 | carry * bit, |
---|
65 | bit * carry |
---|
66 | ) union6 |
---|
67 | | `MOVC of acc * [ acc_dptr | acc_pc ] |
---|
68 | | `MOVX of (acc * [ ext_indirect | ext_indirect_dptr ], |
---|
69 | [ ext_indirect | ext_indirect_dptr ] * acc) union2 |
---|
70 | | `SETB of [ carry | bit ] |
---|
71 | | `PUSH of direct |
---|
72 | | `POP of direct |
---|
73 | | `XCH of acc * [ reg | direct | indirect ] |
---|
74 | | `XCHD of acc * indirect |
---|
75 | |
---|
76 | (* program branching *) |
---|
77 | | `JC of rel |
---|
78 | | `JNC of rel |
---|
79 | | `JB of bit * rel |
---|
80 | | `JNB of bit * rel |
---|
81 | | `JBC of bit * rel |
---|
82 | | `ACALL of addr11 |
---|
83 | | `LCALL of addr16 |
---|
84 | | `RET |
---|
85 | | `RETI |
---|
86 | | `AJMP of addr11 |
---|
87 | | `LJMP of addr16 |
---|
88 | | `SJMP of rel |
---|
89 | | `JMP of indirect_dptr |
---|
90 | | `JZ of rel |
---|
91 | | `JNZ of rel |
---|
92 | | `CJNE of (acc * [ direct | data ], [ reg | indirect ] * data) union2 * rel |
---|
93 | | `DJNZ of [ reg | direct ] * rel |
---|
94 | | `NOP ] |
---|
95 | |
---|
96 | type labelled_instruction = |
---|
97 | [ instruction |
---|
98 | | `Cost of string |
---|
99 | | `Label of string |
---|
100 | | `Jmp of string |
---|
101 | | `Call of string |
---|
102 | ] |
---|