[120] | 1 | open BitVectors;; |
---|
| 2 | |
---|
[27] | 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 | |
---|
[28] | 7 | type direct = [ `DIRECT of byte ] |
---|
[46] | 8 | type indirect = [ `INDIRECT of bit ] |
---|
| 9 | type ext_indirect = [ `EXT_INDIRECT of bit ] |
---|
[28] | 10 | type reg = [ `REG of bit * bit * bit ] |
---|
[27] | 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 ] |
---|
[158] | 18 | type ext_indirect_dptr = [ `EXT_IND_DPTR ] |
---|
[27] | 19 | type indirect_dptr = [ `IND_DPTR ] |
---|
| 20 | type carry = [ `C ] |
---|
[46] | 21 | type bit = [ `BIT of byte ] |
---|
| 22 | type nbit = [ `NBIT of byte ] |
---|
[27] | 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 *) |
---|
[97] | 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 |
---|
[27] | 37 | |
---|
| 38 | (* logical operations *) |
---|
[97] | 39 | | `ANL of |
---|
[28] | 40 | (acc * [ reg | direct | indirect | data ], |
---|
[27] | 41 | direct * [ acc | data ], |
---|
| 42 | carry * [ bit | nbit]) union3 |
---|
[97] | 43 | | `ORL of |
---|
[35] | 44 | (acc * [ reg | data | direct | indirect ], |
---|
[27] | 45 | direct * [ acc | data ], |
---|
| 46 | carry * [ bit | nbit]) union3 |
---|
[97] | 47 | | `XRL of |
---|
[35] | 48 | (acc * [ data | reg | direct | indirect ], |
---|
[27] | 49 | direct * [ acc | data ]) union2 |
---|
[97] | 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 |
---|
[27] | 57 | |
---|
| 58 | (* data transfer *) |
---|
[97] | 59 | | `MOV of |
---|
[27] | 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 |
---|
[97] | 67 | | `MOVC of acc * [ acc_dptr | acc_pc ] |
---|
| 68 | | `MOVX of (acc * [ ext_indirect | ext_indirect_dptr ], |
---|
[46] | 69 | [ ext_indirect | ext_indirect_dptr ] * acc) union2 |
---|
[97] | 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 |
---|
[27] | 75 | |
---|
| 76 | (* program branching *) |
---|
[97] | 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 |
---|
[100] | 98 | | `Cost of string |
---|
[97] | 99 | | `Label of string |
---|
[100] | 100 | | `Jmp of string |
---|
| 101 | | `Call of string |
---|
| 102 | ] |
---|