Changeset 46


Ignore:
Timestamp:
Sep 8, 2010, 6:09:01 PM (8 years ago)
Author:
mulligan
Message:

MOV done.

Location:
Deliverables/D4.1
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/ASM.mli

    r35 r46  
    66
    77type direct = [ `DIRECT of byte ]
    8 type indirect = [ `INDIRECT of bool ]
     8type indirect = [ `INDIRECT of bit ]
     9type ext_indirect = [ `EXT_INDIRECT of bit ]
    910type reg = [ `REG of bit * bit * bit ]
    1011type acc = [ `A ]
     
    1617type acc_pc = [ `A_PC ]
    1718type indirect_dptr = [ `IND_DPTR ]
     19type ext_indirect_dptr = [ `EXT_IND_DPTR ]
    1820type carry = [ `C ]
    19 type bit = [ `BIT of byte7 ]
    20 type nbit = [ `NBIT of byte7 ]
     21type bit = [ `BIT of byte ]
     22type nbit = [ `NBIT of byte ]
    2123type rel = [ `REL of byte ]
    2224type addr11 = [ `ADDR11 of word11 ]
     
    6466     ) union6
    6567 | MOVC of acc * [ acc_dptr | acc_pc ]
    66  | MOVX of (acc * [ indirect | indirect_dptr ],
    67             [ indirect | indirect_dptr ] * acc) union2
     68 | MOVX of (acc * [ ext_indirect | ext_indirect_dptr ],
     69            [ ext_indirect | ext_indirect_dptr ] * acc) union2
    6870 | SETB of [ carry | bit ]
    6971 | PUSH of direct
  • Deliverables/D4.1/ASMInterpret.ml

    r44 r46  
    5454let fetch pmem pc =
    5555 let next pc = pc ++ 1, WordMap.find pc pmem in
    56  let next7 pc =
    57   let pc,v = next pc in
    58    try pc, byte7_of_byte v
    59    with Byte7_conversion -> raise (Fetch_exception "Cannot convert byte7") in
    6056 let instr = WordMap.find pc pmem in
    6157 let pc = pc ++ 1 in
     
    106102       ANL (`U2 (`DIRECT b1,`DATA b2)), pc, 2
    107103   | (true,false,false,false),(false,false,true,false) ->
    108       let pc,b1 = next7 pc in
     104      let pc,b1 = next pc in
    109105       ANL (`U3 (`C,`BIT b1)), pc, 2
    110106   | (true,false,true,true),(false,false,false,false) ->
    111       let pc,b1 = next7 pc in
     107      let pc,b1 = next pc in
    112108       ANL (`U3 (`C,`NBIT b1)), pc, 2
    113109   | (true,false,true,true),(false,true,false,true) ->
     
    132128         CLR `C, pc, 1
    133129   | (true,true,false,false),(false,false,true,false) ->
    134        let pc,b1 = next7 pc in
     130       let pc,b1 = next pc in
    135131         CLR (`BIT b1), pc, 1
    136132   | (true,true,false,true),(false,true,false,false) ->
     
    166162         INC `DPTR, pc, 2
    167163   | (false,false,true,false),(false,false,false,false) ->
    168        let pc,b1 = next7 pc in
     164       let pc,b1 = next pc in
    169165       let pc,b2 = next pc in
    170166         JB (`BIT b1, `REL b2), pc, 2
    171167   | (false,false,false,true),(false,false,false,false) ->
    172        let pc,b1 = next7 pc in
     168       let pc,b1 = next pc in
    173169       let pc,b2 = next pc in
    174170         JBC (`BIT b1, `REL b2), pc, 2
     
    179175         JMP `IND_DPTR, pc, 2
    180176   | (false,false,true,true),(false,false,false,false) ->
    181        let pc,b1 = next7 pc in
     177       let pc,b1 = next pc in
    182178       let pc,b2 = next pc in
    183179         JNB (`BIT b1, `REL b2), pc, 2
     
    243239         MOV (`U2 (`INDIRECT i1, `DATA b1)), pc, 1
    244240   | (true,false,true,false),(false,false,true,false) ->
    245        let pc,b1 = next7 pc in
     241       let pc,b1 = next pc in
    246242         MOV (`U5 (`C, `BIT b1)), pc, 1
    247243   | (true,false,false,true),(false,false,true,false) ->
    248        let pc,b1 = next7 pc in
     244       let pc,b1 = next pc in
    249245         MOV (`U6 (`BIT b1, `C)), pc, 2
    250246   | (true,false,false,true),(false,false,false,false) ->
     
    257253         MOVC (`A, `A_PC), pc, 2
    258254   | (true,true,true,false),(false,false,true,i1) ->
    259          MOVX (`U1 (`A, `INDIRECT i1)), pc, 2
     255         MOVX (`U1 (`A, `EXT_INDIRECT i1)), pc, 2
    260256   | (true,true,true,false),(false,false,false,false) ->
    261          MOVX (`U1 (`A, `IND_DPTR)), pc, 2
     257         MOVX (`U1 (`A, `EXT_IND_DPTR)), pc, 2
    262258   | (true,true,true,true),(false,false,true,i1) ->
    263          MOVX (`U2 (`INDIRECT i1, `A)), pc, 2
     259         MOVX (`U2 (`EXT_INDIRECT i1, `A)), pc, 2
    264260   | (true,true,true,true),(false,false,false,false) ->
    265          MOVX (`U2 (`IND_DPTR, `A)), pc, 2
     261         MOVX (`U2 (`EXT_IND_DPTR, `A)), pc, 2
    266262   | (true,false,true,false),(false,true,false,false) ->
    267263         MUL(`A, `B), pc, 4
     
    286282         ORL (`U2 (`DIRECT b1, `DATA b2)), pc, 2
    287283   | (false,true,true,true),(false,false,true,false) ->
    288        let pc,b1 = next7 pc in
     284       let pc,b1 = next pc in
    289285         ORL (`U3 (`C, `BIT b1)), pc, 2
    290286   | (true,false,true,false),(false,false,false,false) ->
    291        let pc,b1 = next7 pc in
     287       let pc,b1 = next pc in
    292288         ORL (`U3 (`C, `NBIT b1)), pc, 2
    293289   | (true,true,false,true),(false,false,false,false) ->
     
    312308         SETB `C, pc, 1
    313309   | (true,true,false,true),(false,false,true,false) ->
    314        let pc,b1 = next7 pc in
     310       let pc,b1 = next pc in
    315311         SETB (`BIT b1), pc, 1
    316312   | (true,false,false,false),(false,false,false,false) ->
     
    392388     [(false,true,false,true),(false,false,true,true); b1; b2]
    393389  | ANL (`U3 (`C,`BIT b1)) ->
    394      [(true,false,false,false),(false,false,true,false); byte_of_byte7 b1]
     390     [(true,false,false,false),(false,false,true,false); b1]
    395391  | ANL (`U3 (`C,`NBIT b1)) ->
    396     [(true,false,true,true),(false,false,false,false); byte_of_byte7 b1]
     392    [(true,false,true,true),(false,false,false,false); b1]
    397393  | CJNE (`U1 (`A, `DIRECT b1), `REL b2) ->
    398394    [(true,false,true,true),(false,true,false,true); b1; b2]
     
    408404    [(true,true,false,false),(false,false,true,true)]
    409405  | CLR (`BIT b1) ->
    410     [(true,true,false,false),(false,false,true,false); byte_of_byte7 b1]
     406    [(true,true,false,false),(false,false,true,false); b1]
    411407  | DA `A ->
    412408    [(true,true,false,true),(false,true,false,false)]
     
    436432    [(true,false,true,false),(false,false,true,true)]
    437433  | JB (`BIT b1, `REL b2) ->
    438     [(false,false,true,false),(false,false,false,false); byte_of_byte7 b1; b2]
     434    [(false,false,true,false),(false,false,false,false); b1; b2]
    439435  | JBC (`BIT b1, `REL b2) ->
    440     [(false,false,false,true),(false,false,false,false); byte_of_byte7 b1; b2]
     436    [(false,false,false,true),(false,false,false,false); b1; b2]
    441437  | JC (`REL b1) ->
    442438    [(false,true,false,false),(false,false,false,false); b1]
     
    444440    [(false,true,true,true),(false,false,true,true)]
    445441  | JNB (`BIT b1, `REL b2) ->
    446     [(false,false,true,true),(false,false,false,false); byte_of_byte7 b1; b2]
     442    [(false,false,true,true),(false,false,false,false); b1; b2]
    447443  | JNC (`REL b1) ->
    448444    [(false,true,false,true),(false,false,false,false); b1]
     
    486482    [(false,true,true,true),(false,true,true,i1); b1]
    487483  | MOV (`U5 (`C, `BIT b1)) ->
    488     [(true,false,true,false),(false,false,true,false); byte_of_byte7 b1]
     484    [(true,false,true,false),(false,false,true,false); b1]
    489485  | MOV (`U6 (`BIT b1, `C)) ->
    490     [(true,false,false,true),(false,false,true,false); byte_of_byte7 b1]
     486    [(true,false,false,true),(false,false,true,false); b1]
    491487  | MOV (`U4 (`DPTR, `DATA16(b1,b2))) ->
    492488    [(true,false,false,true),(false,false,false,false); b1; b2]
     
    495491  | MOVC (`A, `A_PC) ->
    496492    [(true,false,false,false),(false,false,true,true)]
    497   | MOVX (`U1 (`A, `INDIRECT i1)) ->
     493  | MOVX (`U1 (`A, `EXT_INDIRECT i1)) ->
    498494    [(true,true,true,false),(false,false,true,i1)]
    499   | MOVX (`U1 (`A, `IND_DPTR)) ->
     495  | MOVX (`U1 (`A, `EXT_IND_DPTR)) ->
    500496    [(true,true,true,false),(false,false,false,false)]
    501   | MOVX (`U2 (`INDIRECT i1, `A)) ->
     497  | MOVX (`U2 (`EXT_INDIRECT i1, `A)) ->
    502498    [(true,true,true,true),(false,false,true,i1)]
    503   | MOVX (`U2 (`IND_DPTR, `A)) ->
     499  | MOVX (`U2 (`EXT_IND_DPTR, `A)) ->
    504500    [(true,true,true,true),(false,false,false,false)]
    505501  | MUL(`A, `B) ->
     
    520516    [(false,true,false,false),(false,false,true,true); b1; b2]
    521517  | ORL (`U3 (`C, `BIT b1)) ->
    522     [(false,true,true,true),(false,false,true,false); byte_of_byte7 b1]
     518    [(false,true,true,true),(false,false,true,false); b1]
    523519  | ORL (`U3 (`C, `NBIT b1)) ->
    524     [(true,false,true,false),(false,false,false,false); byte_of_byte7 b1]
     520    [(true,false,true,false),(false,false,false,false); b1]
    525521  | POP (`DIRECT b1) ->
    526522    [(true,true,false,true),(false,false,false,false); b1]
     
    542538    [(true,true,false,true),(false,false,true,true)]
    543539  | SETB (`BIT b1) ->
    544     [(true,true,false,true),(false,false,true,false); byte_of_byte7 b1]
     540    [(true,true,false,true),(false,false,true,false); b1]
    545541  | SJMP (`REL b1) ->
    546542    [(true,false,false,false),(false,false,false,false); b1]
     
    635631;;
    636632
     633let fetch_arg16 status =
     634  function
     635                `DATA16 w -> w
     636
     637let 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
     655let 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
    637672let set_arg8 status v =
    638673 function
     
    664699        WordMap.add dpr v status.external_ram }
    665700;;
     701
     702let set_arg16 status (dh, dl) =
     703        function
     704                `DPTR ->
     705                        { status with dph = dh; dpl = dl }
    666706
    667707let set_flags status c ac ov =
     
    723763      let status = { status with acc = q ; b = r } in
    724764       set_flags status false None false
     765
    725766(*
    726767 | DA  of acc
     
    745786 | RRC of acc
    746787 | 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
    747808
    748809 (* 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(*
    757811 | MOVC of acc * [ acc_dptr | acc_pc ]
    758812 | MOVX of (acc * [ indirect | indirect_dptr ],
  • Deliverables/D4.1/Pretty.ml

    r45 r46  
    1111let pretty_byte =
    1212  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)
    1613
    1714let pretty_word =
     
    3027  | ADD (`A, `DIRECT b1) ->
    3128     "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 ^ ")"
    3259(*
    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]
    6360  | CJNE (`U1 (`A, `DIRECT b1), `REL b2) ->
    6461    [(true,false,true,true),(false,true,false,true); b1; b2]
  • Deliverables/D4.1/physical.ml

    r44 r46  
    2424
    2525let int_of_byte (n1,n2) = int_of_nibble n2 + int_of_nibble n1 * 16
     26
     27let 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
    2629
    2730let int_of_word (b1,b2) = int_of_byte b2 + int_of_byte b1 * 256
     
    113116let byte_of_byte7 (b1,b2,b3,n) =
    114117        (false,b1,b2,b3),n
     118
     119let 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
     130let 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  
    1818val int_of_bit: bit -> int
    1919val int_of_byte: byte -> int
     20val int_of_byte7: byte7 -> int
    2021val int_of_nibble: nibble -> int
    2122val byte7_of_bit: bit -> byte7
     
    3031val dec: byte -> byte (* with roll-over *)
    3132val inc: byte -> byte (* with roll-over *)
     33
     34val nth_bit: int -> byte -> bit
     35val set_nth_bit: int -> bit -> byte -> byte
Note: See TracChangeset for help on using the changeset viewer.