Changeset 46 for Deliverables/D4.1/ASMInterpret.ml
 Timestamp:
 Sep 8, 2010, 6:09:01 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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 ],
Note: See TracChangeset
for help on using the changeset viewer.