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