Changeset 46
 Timestamp:
 Sep 8, 2010, 6:09:01 PM (8 years ago)
 Location:
 Deliverables/D4.1
 Files:

 5 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D4.1/ASM.mli
r35 r46 6 6 7 7 type direct = [ `DIRECT of byte ] 8 type indirect = [ `INDIRECT of bool ] 8 type indirect = [ `INDIRECT of bit ] 9 type ext_indirect = [ `EXT_INDIRECT of bit ] 9 10 type reg = [ `REG of bit * bit * bit ] 10 11 type acc = [ `A ] … … 16 17 type acc_pc = [ `A_PC ] 17 18 type indirect_dptr = [ `IND_DPTR ] 19 type ext_indirect_dptr = [ `EXT_IND_DPTR ] 18 20 type carry = [ `C ] 19 type bit = [ `BIT of byte 7]20 type nbit = [ `NBIT of byte 7]21 type bit = [ `BIT of byte ] 22 type nbit = [ `NBIT of byte ] 21 23 type rel = [ `REL of byte ] 22 24 type addr11 = [ `ADDR11 of word11 ] … … 64 66 ) union6 65 67  MOVC of acc * [ acc_dptr  acc_pc ] 66  MOVX of (acc * [ indirect indirect_dptr ],67 [ indirect indirect_dptr ] * acc) union268  MOVX of (acc * [ ext_indirect  ext_indirect_dptr ], 69 [ ext_indirect  ext_indirect_dptr ] * acc) union2 68 70  SETB of [ carry  bit ] 69 71  PUSH of direct 
Deliverables/D4.1/ASMInterpret.ml
r44 r46 54 54 let fetch pmem pc = 55 55 let next pc = pc ++ 1, WordMap.find pc pmem in 56 let next7 pc =57 let pc,v = next pc in58 try pc, byte7_of_byte v59 with Byte7_conversion > raise (Fetch_exception "Cannot convert byte7") in60 56 let instr = WordMap.find pc pmem in 61 57 let pc = pc ++ 1 in … … 106 102 ANL (`U2 (`DIRECT b1,`DATA b2)), pc, 2 107 103  (true,false,false,false),(false,false,true,false) > 108 let pc,b1 = next 7pc in104 let pc,b1 = next pc in 109 105 ANL (`U3 (`C,`BIT b1)), pc, 2 110 106  (true,false,true,true),(false,false,false,false) > 111 let pc,b1 = next 7pc in107 let pc,b1 = next pc in 112 108 ANL (`U3 (`C,`NBIT b1)), pc, 2 113 109  (true,false,true,true),(false,true,false,true) > … … 132 128 CLR `C, pc, 1 133 129  (true,true,false,false),(false,false,true,false) > 134 let pc,b1 = next 7pc in130 let pc,b1 = next pc in 135 131 CLR (`BIT b1), pc, 1 136 132  (true,true,false,true),(false,true,false,false) > … … 166 162 INC `DPTR, pc, 2 167 163  (false,false,true,false),(false,false,false,false) > 168 let pc,b1 = next 7pc in164 let pc,b1 = next pc in 169 165 let pc,b2 = next pc in 170 166 JB (`BIT b1, `REL b2), pc, 2 171 167  (false,false,false,true),(false,false,false,false) > 172 let pc,b1 = next 7pc in168 let pc,b1 = next pc in 173 169 let pc,b2 = next pc in 174 170 JBC (`BIT b1, `REL b2), pc, 2 … … 179 175 JMP `IND_DPTR, pc, 2 180 176  (false,false,true,true),(false,false,false,false) > 181 let pc,b1 = next 7pc in177 let pc,b1 = next pc in 182 178 let pc,b2 = next pc in 183 179 JNB (`BIT b1, `REL b2), pc, 2 … … 243 239 MOV (`U2 (`INDIRECT i1, `DATA b1)), pc, 1 244 240  (true,false,true,false),(false,false,true,false) > 245 let pc,b1 = next 7pc in241 let pc,b1 = next pc in 246 242 MOV (`U5 (`C, `BIT b1)), pc, 1 247 243  (true,false,false,true),(false,false,true,false) > 248 let pc,b1 = next 7pc in244 let pc,b1 = next pc in 249 245 MOV (`U6 (`BIT b1, `C)), pc, 2 250 246  (true,false,false,true),(false,false,false,false) > … … 257 253 MOVC (`A, `A_PC), pc, 2 258 254  (true,true,true,false),(false,false,true,i1) > 259 MOVX (`U1 (`A, ` INDIRECT i1)), pc, 2255 MOVX (`U1 (`A, `EXT_INDIRECT i1)), pc, 2 260 256  (true,true,true,false),(false,false,false,false) > 261 MOVX (`U1 (`A, ` IND_DPTR)), pc, 2257 MOVX (`U1 (`A, `EXT_IND_DPTR)), pc, 2 262 258  (true,true,true,true),(false,false,true,i1) > 263 MOVX (`U2 (` INDIRECT i1, `A)), pc, 2259 MOVX (`U2 (`EXT_INDIRECT i1, `A)), pc, 2 264 260  (true,true,true,true),(false,false,false,false) > 265 MOVX (`U2 (` IND_DPTR, `A)), pc, 2261 MOVX (`U2 (`EXT_IND_DPTR, `A)), pc, 2 266 262  (true,false,true,false),(false,true,false,false) > 267 263 MUL(`A, `B), pc, 4 … … 286 282 ORL (`U2 (`DIRECT b1, `DATA b2)), pc, 2 287 283  (false,true,true,true),(false,false,true,false) > 288 let pc,b1 = next 7pc in284 let pc,b1 = next pc in 289 285 ORL (`U3 (`C, `BIT b1)), pc, 2 290 286  (true,false,true,false),(false,false,false,false) > 291 let pc,b1 = next 7pc in287 let pc,b1 = next pc in 292 288 ORL (`U3 (`C, `NBIT b1)), pc, 2 293 289  (true,true,false,true),(false,false,false,false) > … … 312 308 SETB `C, pc, 1 313 309  (true,true,false,true),(false,false,true,false) > 314 let pc,b1 = next 7pc in310 let pc,b1 = next pc in 315 311 SETB (`BIT b1), pc, 1 316 312  (true,false,false,false),(false,false,false,false) > … … 392 388 [(false,true,false,true),(false,false,true,true); b1; b2] 393 389  ANL (`U3 (`C,`BIT b1)) > 394 [(true,false,false,false),(false,false,true,false); byte_of_byte7b1]390 [(true,false,false,false),(false,false,true,false); b1] 395 391  ANL (`U3 (`C,`NBIT b1)) > 396 [(true,false,true,true),(false,false,false,false); byte_of_byte7b1]392 [(true,false,true,true),(false,false,false,false); b1] 397 393  CJNE (`U1 (`A, `DIRECT b1), `REL b2) > 398 394 [(true,false,true,true),(false,true,false,true); b1; b2] … … 408 404 [(true,true,false,false),(false,false,true,true)] 409 405  CLR (`BIT b1) > 410 [(true,true,false,false),(false,false,true,false); byte_of_byte7b1]406 [(true,true,false,false),(false,false,true,false); b1] 411 407  DA `A > 412 408 [(true,true,false,true),(false,true,false,false)] … … 436 432 [(true,false,true,false),(false,false,true,true)] 437 433  JB (`BIT b1, `REL b2) > 438 [(false,false,true,false),(false,false,false,false); byte_of_byte7b1; b2]434 [(false,false,true,false),(false,false,false,false); b1; b2] 439 435  JBC (`BIT b1, `REL b2) > 440 [(false,false,false,true),(false,false,false,false); byte_of_byte7b1; b2]436 [(false,false,false,true),(false,false,false,false); b1; b2] 441 437  JC (`REL b1) > 442 438 [(false,true,false,false),(false,false,false,false); b1] … … 444 440 [(false,true,true,true),(false,false,true,true)] 445 441  JNB (`BIT b1, `REL b2) > 446 [(false,false,true,true),(false,false,false,false); byte_of_byte7b1; b2]442 [(false,false,true,true),(false,false,false,false); b1; b2] 447 443  JNC (`REL b1) > 448 444 [(false,true,false,true),(false,false,false,false); b1] … … 486 482 [(false,true,true,true),(false,true,true,i1); b1] 487 483  MOV (`U5 (`C, `BIT b1)) > 488 [(true,false,true,false),(false,false,true,false); byte_of_byte7b1]484 [(true,false,true,false),(false,false,true,false); b1] 489 485  MOV (`U6 (`BIT b1, `C)) > 490 [(true,false,false,true),(false,false,true,false); byte_of_byte7b1]486 [(true,false,false,true),(false,false,true,false); b1] 491 487  MOV (`U4 (`DPTR, `DATA16(b1,b2))) > 492 488 [(true,false,false,true),(false,false,false,false); b1; b2] … … 495 491  MOVC (`A, `A_PC) > 496 492 [(true,false,false,false),(false,false,true,true)] 497  MOVX (`U1 (`A, ` INDIRECT i1)) >493  MOVX (`U1 (`A, `EXT_INDIRECT i1)) > 498 494 [(true,true,true,false),(false,false,true,i1)] 499  MOVX (`U1 (`A, ` IND_DPTR)) >495  MOVX (`U1 (`A, `EXT_IND_DPTR)) > 500 496 [(true,true,true,false),(false,false,false,false)] 501  MOVX (`U2 (` INDIRECT i1, `A)) >497  MOVX (`U2 (`EXT_INDIRECT i1, `A)) > 502 498 [(true,true,true,true),(false,false,true,i1)] 503  MOVX (`U2 (` IND_DPTR, `A)) >499  MOVX (`U2 (`EXT_IND_DPTR, `A)) > 504 500 [(true,true,true,true),(false,false,false,false)] 505 501  MUL(`A, `B) > … … 520 516 [(false,true,false,false),(false,false,true,true); b1; b2] 521 517  ORL (`U3 (`C, `BIT b1)) > 522 [(false,true,true,true),(false,false,true,false); byte_of_byte7b1]518 [(false,true,true,true),(false,false,true,false); b1] 523 519  ORL (`U3 (`C, `NBIT b1)) > 524 [(true,false,true,false),(false,false,false,false); byte_of_byte7b1]520 [(true,false,true,false),(false,false,false,false); b1] 525 521  POP (`DIRECT b1) > 526 522 [(true,true,false,true),(false,false,false,false); b1] … … 542 538 [(true,true,false,true),(false,false,true,true)] 543 539  SETB (`BIT b1) > 544 [(true,true,false,true),(false,false,true,false); byte_of_byte7b1]540 [(true,true,false,true),(false,false,true,false); b1] 545 541  SJMP (`REL b1) > 546 542 [(true,false,false,false),(false,false,false,false); b1] … … 635 631 ;; 636 632 633 let fetch_arg16 status = 634 function 635 `DATA16 w > w 636 637 let fetch_arg1 status = 638 function 639 `BIT addr 640  `NBIT addr as x > 641 let res = 642 (match addr with 643 (false,r1,r2,r3),n1 > 644 let addr = (int_of_byte7 (r1,r2,r3,n1)) in 645 let addr' = byte7_of_int ((addr / 8) + 32) in 646 nth_bit (addr mod 8) (Byte7Map.find addr' status.low_internal_ram) 647  (true,r1,r2,r3),n1 > 648 (*CSC: SFR access, TO BE IMPLEMENTED *) 649 assert false) 650 in (match x with `BIT _ > res  _ > not res) 651  `C > 652 let ((b1,_,_,_),_) = status.psw in 653 b1 654 655 let set_arg1 status v = 656 function 657 `BIT addr > 658 (match addr with 659 (false,r1,r2,r3),n1 > 660 let addr = (int_of_byte7 (r1,r2,r3,n1)) in 661 let addr' = byte7_of_int ((addr / 8) + 32) in 662 { status with low_internal_ram = 663 Byte7Map.add addr' (set_nth_bit (addr mod 8) v (Byte7Map.find addr' status.low_internal_ram)) status.low_internal_ram } 664  (true,r1,r2,r3),n1 > 665 (*CSC: SFR access, TO BE IMPLEMENTED *) 666 (* assert false for now. Try to understand what DEC really does *) 667 assert false) 668  `C > 669 let ((_,b2,b3,b4),n2) = status.psw in 670 { status with psw = (v,b2,b3,b4),n2 } 671 637 672 let set_arg8 status v = 638 673 function … … 664 699 WordMap.add dpr v status.external_ram } 665 700 ;; 701 702 let set_arg16 status (dh, dl) = 703 function 704 `DPTR > 705 { status with dph = dh; dpl = dl } 666 706 667 707 let set_flags status c ac ov = … … 723 763 let status = { status with acc = q ; b = r } in 724 764 set_flags status false None false 765 725 766 (* 726 767  DA of acc … … 745 786  RRC of acc 746 787  SWAP of acc 788 *) 789 790  MOV(`U1(b1, b2)) > 791 let arg = fetch_arg8 status b2 in 792 set_arg8 status arg b1 793  MOV(`U2(b1, b2)) > 794 let arg = fetch_arg8 status b2 in 795 set_arg8 status arg b1 796  MOV(`U3(b1, b2)) > 797 let arg = fetch_arg8 status b2 in 798 set_arg8 status arg b1 799  MOV(`U4(b1,b2)) > 800 let arg = fetch_arg16 status b2 in 801 set_arg16 status arg b1 802  MOV(`U5(b1,b2))> 803 let arg = fetch_arg1 status b2 in 804 set_arg1 status arg b1 805  MOV(`U6(b1,b2))> 806 let arg = fetch_arg1 status b2 in 807 set_arg1 status arg b1 747 808 748 809 (* data transfer *) 749  MOV of 750 (acc * [ reg  direct  indirect  data ], 751 [ reg  indirect ] * [ acc  direct  data ], 752 direct * [ acc  reg  direct  indirect  data ], 753 dptr * data16, 754 carry * bit, 755 bit * carry 756 ) union6 810 (* 757 811  MOVC of acc * [ acc_dptr  acc_pc ] 758 812  MOVX of (acc * [ indirect  indirect_dptr ], 
Deliverables/D4.1/Pretty.ml
r45 r46 11 11 let pretty_byte = 12 12 function (n1, n2) > pretty_nibble n1 ^ " " ^ pretty_nibble n2 13 14 let pretty_byte7 =15 function (b1,b2,b3,n) > "byte7: " ^ pretty_byte ((false,b1,b2,b3), n)16 13 17 14 let pretty_word = … … 30 27  ADD (`A, `DIRECT b1) > 31 28 "ADD A direct (" ^ pretty_byte b1 ^ ")" 29  ADD (`A, `INDIRECT i1) > 30 "ADD A @Ri (" ^ pretty_bit i1 ^ ")" 31  ADD (`A, `DATA b1) > 32 "ADD A #data (" ^ pretty_byte b1 ^ ")" 33  ADDC (`A, `REG(r1,r2,r3)) > 34 "ADDC A Rn (" ^ pretty_bit r1 ^ pretty_bit r2 ^ pretty_bit r3 ^ ")" 35  ADDC (`A, `DIRECT b1) > 36 "ADDC A direct (" ^ pretty_byte b1 ^ ")" 37  ADDC (`A,`INDIRECT i1) > 38 "ADDC A @Ri (" ^ pretty_bit i1 ^ ")" 39  ADDC (`A,`DATA b1) > 40 "ADDC A #data (" ^ pretty_byte b1 ^ ")" 41  AJMP (`ADDR11 (a10,a9,a8,b1)) > 42 "AJMP addr11 (" ^ pretty_word11 (a10,a9,a8,b1) ^ ")" 43  ANL (`U1 (`A, `REG (r1,r2,r3))) > 44 "ANL A Rn (" ^ pretty_bit r1 ^ pretty_bit r2 ^ pretty_bit r3 ^ ")" 45  ANL (`U1 (`A, `DIRECT b1)) > 46 "ANL A direct (" ^ pretty_byte b1 ^ ")" 47  ANL (`U1 (`A, `INDIRECT i1)) > 48 "ANL A @Ri (" ^ pretty_bit i1 ^ ")" 49  ANL (`U1 (`A, `DATA b1)) > 50 "ANL A #data (" ^ pretty_byte b1 ^ ")" 51  ANL (`U2 (`DIRECT b1,`A)) > 52 "ANL direct A (" ^ pretty_byte b1 ^ ")" 53  ANL (`U2 (`DIRECT b1,`DATA b2)) > 54 "ANL direct #data (" ^ pretty_byte b1 ^ pretty_byte b2 ^ ")" 55  ANL (`U3 (`C,`BIT b1)) > 56 "ANL C bit (" ^ pretty_byte b1 ^ ")" 57  ANL (`U3 (`C,`NBIT b1)) > 58 "ANL C /bit (" ^ pretty_byte b1 ^ ")" 32 59 (* 33  ADD (`A, `INDIRECT i1) >34 [(false,false,true,false),(false,true,true,i1)]35  ADD (`A, `DATA b1) >36 [(false,false,true,false),(false,true,false,false); b1]37  ADDC (`A, `REG(r1,r2,r3)) >38 [(false,false,true,true),(true,r1,r2,r3)]39  ADDC (`A, `DIRECT b1) >40 [(false,false,true,true),(false,true,false,true); b1]41  ADDC (`A,`INDIRECT i1) >42 [(false,false,true,true),(false,true,true,i1)]43  ADDC (`A,`DATA b1) >44 [(false,false,true,true),(false,true,false,false); b1]45  AJMP (`ADDR11 (a10,a9,a8,b1)) >46 [(a10,a9,a8,false),(false,false,false,true)]47  ANL (`U1 (`A, `REG (r1,r2,r3))) >48 [(false,true,false,true),(true,r1,r2,r3)]49  ANL (`U1 (`A, `DIRECT b1)) >50 [(false,true,false,true),(false,true,false,true); b1]51  ANL (`U1 (`A, `INDIRECT i1)) >52 [(false,true,false,true),(false,true,true,i1)]53  ANL (`U1 (`A, `DATA b1)) >54 [(false,true,false,true),(false,true,false,false); b1]55  ANL (`U2 (`DIRECT b1,`A)) >56 [(false,true,false,true),(false,false,true,false); b1]57  ANL (`U2 (`DIRECT b1,`DATA b2)) >58 [(false,true,false,true),(false,false,true,true); b1; b2]59  ANL (`U3 (`C,`BIT b1)) >60 [(true,false,false,false),(false,false,true,false); byte_of_byte7 b1]61  ANL (`U3 (`C,`NBIT b1)) >62 [(true,false,true,true),(false,false,false,false); byte_of_byte7 b1]63 60  CJNE (`U1 (`A, `DIRECT b1), `REL b2) > 64 61 [(true,false,true,true),(false,true,false,true); b1; b2] 
Deliverables/D4.1/physical.ml
r44 r46 24 24 25 25 let int_of_byte (n1,n2) = int_of_nibble n2 + int_of_nibble n1 * 16 26 27 let int_of_byte7 (b1,b2,b3,n2) = int_of_nibble n2 + int_of_bit b3 * 16 + 28 int_of_bit b2 * 32 + int_of_bit b1 * 64 26 29 27 30 let int_of_word (b1,b2) = int_of_byte b2 + int_of_byte b1 * 256 … … 113 116 let byte_of_byte7 (b1,b2,b3,n) = 114 117 (false,b1,b2,b3),n 118 119 let nth_bit pos ((b1,b2,b3,b4),(b5,b6,b7,b8)) = 120 match pos with 121 0 > b1 122  1 > b2 123  2 > b3 124  3 > b4 125  4 > b5 126  5 > b6 127  6 > b7 128  7 > b8 129 130 let set_nth_bit pos v ((b1,b2,b3,b4) as n1,((b5,b6,b7,b8) as n2)) = 131 match pos with 132 0 > ((v,b2,b3,b4),n2) 133  1 > ((b1,v,b3,b4),n2) 134  2 > ((b1,b2,v,b4),n2) 135  3 > ((b1,b2,b3,v),n2) 136  4 > (n1,(v,b6,b7,b8)) 137  5 > (n1,(b5,v,b7,b8)) 138  6 > (n1,(b5,b6,v,b8)) 139  7 > (n1,(b5,b6,b7,v)) 
Deliverables/D4.1/physical.mli
r44 r46 18 18 val int_of_bit: bit > int 19 19 val int_of_byte: byte > int 20 val int_of_byte7: byte7 > int 20 21 val int_of_nibble: nibble > int 21 22 val byte7_of_bit: bit > byte7 … … 30 31 val dec: byte > byte (* with rollover *) 31 32 val inc: byte > byte (* with rollover *) 33 34 val nth_bit: int > byte > bit 35 val set_nth_bit: int > bit > byte > byte
Note: See TracChangeset
for help on using the changeset viewer.