Changeset 90


Ignore:
Timestamp:
Sep 20, 2010, 1:45:10 PM (9 years ago)
Author:
mulligan
Message:

Ported physical.ml to be compatible with new bitvector code, started
porting ASMInterpret.

Location:
Deliverables/D4.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/ASMInterpret.ml

    r83 r90  
    11open Physical;;
    2 open ASM;;
    3 open Pretty;;
    42
    53exception Fetch_exception of string
    64
    75type time = int;;
    8 
    9 type foo
    106
    117(* no differentiation between internal and external code memory *)
     
    1511   high_internal_ram: byte Byte7Map.t;
    1612   external_ram: byte WordMap.t;
    17 
    18    
    1913
    2014   pc: word;
     
    4741   timer1: word;
    4842   timer2: word;  (* can be missing *)
    49    io: foo (*(time * ?line? -> ?val?)*)
     43   io: time * int -> byte option
    5044 }
    5145
    52 let carr status = let (c,_,_,_),_ = status.psw in c
     46let empty = {
     47  code_memory = WordMap.empty;
     48  low_internal_ram = Byte7Map.empty;
     49  high_internal_ram = Byte7Map.empty;
     50  external_ram = WordMap.empty;
     51
     52  pc = zero `Sixteen;
     53
     54  p0 = zero `Eight;
     55  sp = zero `Eight;
     56  dpl = zero `Eight;
     57  dph = zero `Eight;
     58  pcon = zero `Eight;
     59  tcon = zero `Eight;
     60  tmod = zero `Eight;
     61  tl0 = zero `Eight;
     62  tl1 = zero `Eight;
     63  th0 = zero `Eight;
     64  th1 = zero `Eight;
     65  p1 = zero `Eight;
     66  scon = zero `Eight;
     67  sbuf = zero `Eight;
     68  p2 = zero `Eight;
     69  ie = zero `Eight;
     70  p3 = zero `Eight;
     71  ip = zero `Eight;
     72  psw = zero `Eight;
     73  acc = zero `Eight;
     74  b = zero `Eight;
     75  clock = 0;
     76  timer0 = zero `Sixteen;
     77  timer1 = zero `Sixteen;
     78  timer2 = zero `Sixteen;
     79
     80  io = (fun (time, line) -> None)
     81}
     82
     83let get_cy_flag status =
     84  let (cy,_,_,_),_ = status.psw in cy
     85let get_ac_flag status =
     86  let (_,ac,_,_),_ = status.psw in ac
     87let get_fo_flag status =
     88  let (_,_,fo,_),_ = status.psw in fo
     89let get_rs1_flag status =
     90  let (_,_,_,rs1),_ = status.psw in rs1
     91let get_rs0_flag status =
     92  let _,(rs0,_,_,_) = status.psw in rs0
     93let get_ov_flag status =
     94  let _,(_,ov,_,_) = status.psw in ov
     95let get_ud_flag status =
     96  let _,(_,_,ud,_) = status.psw in ud
     97let get_p_flag status =
     98  let _,(_,_,_,p) = status.psw in p
    5399
    54100(* timings taken from SIEMENS *)
     
    590636;;
    591637
    592 let address_of_register status (b1,b2,b3) =
     638let get_address_of_register status (b1,b2,b3) =
    593639 let (_,_,rs1,rs0),_ = status.psw in
    594640 let base =
     
    602648;;
    603649
    604 let fetch_register status reg =
    605  let addr = address_of_register status reg in
    606   Byte7Map.find addr status.low_internal_ram
     650let get_register status reg =
     651  let addr = address_of_register status reg in
     652    Byte7Map.find addr status.low_internal_ram
    607653;;
    608654
    609655let set_register status v reg =
    610  let addr = address_of_register status reg in
    611   { status with low_internal_ram =
    612      Byte7Map.add addr v status.low_internal_ram }
     656  let addr = address_of_register status reg in
     657    { status with low_internal_ram =
     658        Byte7Map.add addr v status.low_internal_ram }
    613659;;
    614660
    615 let fetch_arg8 status =
     661let get_arg_8 status =
    616662 function
    617663    `DIRECT addr ->
    618       (match addr with
    619          (false,r1,r2,r3),n1 ->
    620            Byte7Map.find (r1,r2,r3,n1) status.low_internal_ram
    621        | (true,r1,r2,r3),n1 ->
    622            (*CSC: SFR access, TO BE IMPLEMENTED *)
    623            assert false)
     664       (match addr with
     665          (false,r1,r2,r3),n1 ->
     666            Byte7Map.find (r1,r2,r3,n1) status.low_internal_ram
     667        | (true,r1,r2,r3),n1 ->
     668             (*CSC: SFR access, TO BE IMPLEMENTED *)
     669            assert false)
    624670  | `INDIRECT b ->
    625      let addr = fetch_register status (false,false,b) in
    626      (match addr with
    627          (false,r1,r2,r3),n1 ->
    628            Byte7Map.find (r1,r2,r3,n1) status.low_internal_ram
    629        | (true,r1,r2,r3),n1 ->
    630            Byte7Map.find (r1,r2,r3,n1) status.high_internal_ram)
    631   | `REG (b1,b2,b3) ->
    632       fetch_register status (b1,b2,b3)
     671       let addr = get_register status (false,false,b) in
     672         (match addr with
     673           (false,r1,r2,r3),n1 ->
     674             Byte7Map.find (r1,r2,r3,n1) status.low_internal_ram
     675         | (true,r1,r2,r3),n1 ->
     676             Byte7Map.find (r1,r2,r3,n1) status.high_internal_ram)
     677  | `REG (b1,b2,b3) -> get_register status (b1,b2,b3)
    633678  | `A -> status.acc
    634679  | `B -> status.b
    635680  | `DATA b -> b
    636681  | `A_DPTR ->
    637      let dpr = status.dph,status.dpl in
    638      (* CSC: what is the right behaviour in case of overflow?
    639         assert false for now. Try to understand what DEC really does *)
    640      let addr = dpr ++ (int_of_byte status.acc) in
    641       WordMap.find addr status.external_ram
     682       let dpr = status.dph,status.dpl in
     683       (* CSC: what is the right behaviour in case of overflow?
     684          assert false for now. Try to understand what DEC really does *)
     685       let addr = dpr ++ (int_of_vect `Eight status.acc) in
     686         WordMap.find addr status.external_ram
    642687  | `A_PC ->
    643      (* CSC: what is the right behaviour in case of overflow?
    644         assert false for now *)
    645      let addr = status.pc ++ (int_of_byte status.acc) in
    646       WordMap.find addr status.external_ram
     688       (* CSC: what is the right behaviour in case of overflow?
     689          assert false for now *)
     690       let addr = status.pc ++ (int_of_vect `Eight status.acc) in
     691         WordMap.find addr status.external_ram
    647692  | `IND_DPTR ->
    648      let dpr = status.dph,status.dpl in
    649       WordMap.find dpr status.external_ram
     693       let dpr = status.dph, status.dpl in
     694         WordMap.find dpr status.external_ram
    650695;;
    651696
    652 let fetch_arg16 status =
     697let get_arg_16 status =
    653698  function
    654699                `DATA16 w -> w
    655700
    656 let fetch_arg1 status =
     701let get_arg_1 status =
    657702  function
    658703    `BIT addr
     
    661706      (match addr with
    662707         (false,r1,r2,r3),n1 ->
    663            let addr = (int_of_byte7 (r1,r2,r3,n1)) in
    664            let addr' = byte7_of_int ((addr / 8) + 32) in
    665             nth_bit (addr mod 8) (Byte7Map.find addr' status.low_internal_ram)
     708           let addr = (int_of_vect `Seven (r1,r2,r3,n1)) in
     709           let addr' = vect_of_int ((addr / 8) + 32) in
     710             nth_bit (addr mod 8) (Byte7Map.find addr' status.low_internal_ram)
    666711       | (true,r1,r2,r3),n1 ->
    667712           (*CSC: SFR access, TO BE IMPLEMENTED *)
     
    669714    in (match x with `BIT _ -> res | _ -> not res)
    670715  | `C ->
    671        let ((b1,_,_,_),_) = status.psw in
    672          b1
     716       let ((b1,_,_,_),_) = status.psw in b1
    673717
    674718let set_arg1 status v =
     
    677721      (match addr with
    678722         (false,r1,r2,r3),n1 ->
    679            let addr = (int_of_byte7 (r1,r2,r3,n1)) in
    680            let addr' = byte7_of_int ((addr / 8) + 32) in
     723           let addr = (int_of_vect `Seven (r1,r2,r3,n1)) in
     724           let addr' = vect_of_int ((addr / 8) + 32) in
    681725            { status with low_internal_ram =
    682726                Byte7Map.add addr' (set_nth_bit (addr mod 8) v (Byte7Map.find addr' status.low_internal_ram)) status.low_internal_ram }
     
    701745           assert false)
    702746  | `INDIRECT b ->
    703      let addr = fetch_register status (false,false,b) in
     747     let addr = get_register status (false,false,b) in
    704748     (match addr with
    705749         (false,r1,r2,r3),n1 ->
     
    740784;;
    741785
    742 let power_on =
    743   status
    744   {
    745     code_memory = WordMap.empty;
    746     external_memory = WordMap.empty;
    747     low_internal_ram = Byte7Map.empty;
    748     high_internal_ram = Byte7Map.empty;
    749 
    750     pc =
    751   }
    752 ;;
    753  
    754 
    755786let execute1 status =
    756787 let instr,pc,ticks = fetch status.code_memory status.pc in
     
    759790     ADD (`A,d1) ->
    760791      let v,c,ac,ov =
    761        add8_with_c (fetch_arg8 status `A) (fetch_arg8 status d1) false
     792       add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) false
    762793      in
    763794       set_flags (set_arg8 status v `A) c (Some ac) ov
    764795   | ADDC (`A,d1) ->
    765796      let v,c,ac,ov =
    766        add8_with_c (fetch_arg8 status `A) (fetch_arg8 status d1) (carr status)
     797       add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (carr status)
    767798      in
    768799       set_flags (set_arg8 status v `A) c (Some ac) ov
    769800   | SUBB (`A,d1) ->
    770801      let v,c,ac,ov =
    771        subb8_with_c (fetch_arg8 status `A) (fetch_arg8 status d1) (carr status)
     802       subb8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (carr status)
    772803      in
    773804       set_flags (set_arg8 status v `A) c (Some ac) ov
     
    784815           status
    785816   | INC ((`A | `REG _ | `DIRECT _ | `INDIRECT _) as d) ->
    786       let b = fetch_arg8 status d in
     817      let b = get_arg_8 status d in
    787818      let res = inc b in
    788819       set_arg8 status res d
    789820   | DEC d ->
    790       let b = fetch_arg8 status d in
     821      let b = get_arg_8 status d in
    791822      let res = dec b in
    792823       set_arg8 status res d
     
    847878 (* logical operations *)
    848879 | ANL (`U1(`A, ag)) ->
    849      let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = fetch_arg8 status `A in
    850      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     880     let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = get_arg_8 status `A in
     881     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    851882     let and_val = ((ac1 && ag1, ac2 && ag2, ac3 && ag3, ac4 && ag4),
    852883                   (ac5 && ag5, ac6 && ag6, ac7 && ag7, ac8 && ag8)) in
    853884       set_arg8 status and_val `A
    854885 | ANL (`U2((`DIRECT d), ag)) ->
    855      let (d1,d2,d3,d4),(d5,d6,d7,d8) = fetch_arg8 status (`DIRECT d) in
    856      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     886     let (d1,d2,d3,d4),(d5,d6,d7,d8) = get_arg_8 status (`DIRECT d) in
     887     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    857888     let and_val = ((d1 && ag1, d2 && ag2, d3 && ag3, d4 && ag4),
    858889                   (d5 && ag5, d6 && ag6, d7 && ag7, d8 && ag8)) in
     
    860891 | ANL (`U3 (`C, (`BIT b))) ->
    861892     let (cy,ac,fo,rs1),(rs0,ov,ud,p) = status.psw in
    862      let c = fetch_arg1 status `C in
    863      let ag_val = fetch_arg1 status (`BIT b) in
     893     let c = get_arg_1 status `C in
     894     let ag_val = get_arg_1 status (`BIT b) in
    864895       { status with psw = (c && ag_val,ac,fo,rs1),(rs0,ov,ud,p) }
    865896 | ANL (`U3 (`C, (`NBIT b))) ->
    866897     let (cy,ac,fo,rs1),(rs0,ov,ud,p) = status.psw in
    867      let c = fetch_arg1 status `C in
    868      let ag_val = not (fetch_arg1 status (`NBIT b)) in
     898     let c = get_arg_1 status `C in
     899     let ag_val = not (get_arg_1 status (`NBIT b)) in
    869900       { status with psw = (c && ag_val,ac,fo,rs1),(rs0,ov,ud,p) }
    870901 | ORL (`U1(`A, ag)) ->
    871      let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = fetch_arg8 status `A in
    872      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     902     let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = get_arg_8 status `A in
     903     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    873904     let and_val = ((ac1 || ag1, ac2 || ag2, ac3 || ag3, ac4 || ag4),
    874905                   (ac5 || ag5, ac6 || ag6, ac7 || ag7, ac8 || ag8)) in
    875906       set_arg8 status and_val `A
    876907 | ORL (`U2((`DIRECT d), ag)) ->
    877      let (d1,d2,d3,d4),(d5,d6,d7,d8) = fetch_arg8 status (`DIRECT d) in
    878      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     908     let (d1,d2,d3,d4),(d5,d6,d7,d8) = get_arg_8 status (`DIRECT d) in
     909     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    879910     let and_val = ((d1 || ag1, d2 || ag2, d3 || ag3, d4 || ag4),
    880911                   (d5 || ag5, d6 || ag6, d7 || ag7, d8 || ag8)) in
     
    882913 | ORL (`U3 (`C, (`BIT b))) ->
    883914     let (cy,ac,fo,rs1),(rs0,ov,ud,p) = status.psw in
    884      let c = fetch_arg1 status `C in
    885      let ag_val = fetch_arg1 status (`BIT b) in
     915     let c = get_arg_1 status `C in
     916     let ag_val = get_arg_1 status (`BIT b) in
    886917       { status with psw = (c || ag_val,ac,fo,rs1),(rs0,ov,ud,p) }
    887918 | ORL (`U3 (`C, (`NBIT b))) ->
    888919     let (cy,ac,fo,rs1),(rs0,ov,ud,p) = status.psw in
    889      let c = fetch_arg1 status `C in
    890      let ag_val = not (fetch_arg1 status (`NBIT b)) in
     920     let c = get_arg_1 status `C in
     921     let ag_val = not (get_arg_1 status (`NBIT b)) in
    891922       { status with psw = (c || ag_val,ac,fo,rs1),(rs0,ov,ud,p) }
    892923 | XRL (`U1(`A, ag)) ->
    893      let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = fetch_arg8 status `A in
    894      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     924     let (ac1,ac2,ac3,ac4),(ac5,ac6,ac7,ac8) = get_arg_8 status `A in
     925     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    895926     let and_val = ((xor ac1 ag1, xor ac2 ag2, xor ac3 ag3, xor ac4 ag4),
    896927                   (xor ac5 ag5, xor ac6 ag6, xor ac7 ag7, xor ac8 ag8)) in
    897928       set_arg8 status and_val `A
    898929 | XRL (`U2((`DIRECT d), ag)) ->
    899      let (d1,d2,d3,d4),(d5,d6,d7,d8) = fetch_arg8 status (`DIRECT d) in
    900      let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = fetch_arg8 status ag in
     930     let (d1,d2,d3,d4),(d5,d6,d7,d8) = get_arg_8 status (`DIRECT d) in
     931     let (ag1,ag2,ag3,ag4),(ag5,ag6,ag7,ag8) = get_arg_8 status ag in
    901932     let and_val = ((xor d1 ag1, xor d2 ag2, xor d3 ag3, xor d4 ag4),
    902933                   (xor d5 ag5, xor d6 ag6, xor d7 ag7, xor d8 ag8)) in
     
    909940     set_arg1 status false a
    910941 | CPL `A ->
    911      let acc_val = fetch_arg8 status `A in
     942     let acc_val = get_arg_8 status `A in
    912943       { status with acc = complement acc_val }
    913944 | CPL `C ->
    914      let ag_val = fetch_arg1 status `C in
     945     let ag_val = get_arg_1 status `C in
    915946       set_arg1 status (not ag_val) `C
    916947 | CPL (`BIT b) ->
    917      let ag_val = fetch_arg1 status (`BIT b) in
     948     let ag_val = get_arg_1 status (`BIT b) in
    918949       set_arg1 status (not ag_val) (`BIT b)
    919950 | RL `A ->
     
    937968       { status with acc = (acc_n_2, acc_n_1) }
    938969 | MOV(`U1(b1, b2)) ->
    939                 let arg = fetch_arg8 status b2 in
     970                let arg = get_arg_8 status b2 in
    940971      set_arg8 status arg b1
    941972 | MOV(`U2(b1, b2)) ->
    942                 let arg = fetch_arg8 status b2 in
     973                let arg = get_arg_8 status b2 in
    943974      set_arg8 status arg b1
    944975 | MOV(`U3(b1, b2)) ->
    945                 let arg = fetch_arg8 status b2 in
     976                let arg = get_arg_8 status b2 in
    946977      set_arg8 status arg b1
    947978 | MOV(`U4(b1,b2)) ->
    948     let arg = fetch_arg16 status b2 in
     979    let arg = get_arg_16 status b2 in
    949980      set_arg16 status arg b1
    950981 | MOV(`U5(b1,b2))->
    951     let arg = fetch_arg1 status b2 in
     982    let arg = get_arg_1 status b2 in
    952983      set_arg1 status arg b1
    953984 | MOV(`U6(b1,b2))->
    954     let arg = fetch_arg1 status b2 in
     985    let arg = get_arg_1 status b2 in
    955986      set_arg1 status arg b1
    956987 | MOVC (`A, `A_DPTR) ->
     
    9831014       status
    9841015 | XCH(`A, arg) ->
    985      let old_arg = fetch_arg8 status arg in
     1016     let old_arg = get_arg_8 status arg in
    9861017     let old_acc = status.acc in
    9871018     let new_status = set_arg8 status old_acc arg in
    9881019       { new_status with acc = old_arg }
    9891020 | XCHD(`A, (`INDIRECT i)) ->
    990      let ((a1,a2,a3,a4),(a5,a6,a7,a8)) = fetch_arg8 status `A in
    991      let ((i1,i2,i3,i4),(i5,i6,i7,i8)) = fetch_arg8 status (`INDIRECT i) in
     1021     let ((a1,a2,a3,a4),(a5,a6,a7,a8)) = get_arg_8 status `A in
     1022     let ((i1,i2,i3,i4),(i5,i6,i7,i8)) = get_arg_8 status (`INDIRECT i) in
    9921023     let new_acc_val = ((a1,a2,a3,a4),(i5,i6,i7,i8)) in
    9931024     let new_reg_val = ((i1,i2,i3,i4),(a5,a6,a7,a8)) in
     
    10091040         status
    10101041 | JB ((`BIT b1), (`REL rel)) ->
    1011      let val_bit = fetch_arg1 status (`BIT b1) in
     1042     let val_bit = get_arg_1 status (`BIT b1) in
    10121043       if val_bit = true then
    10131044         { status with pc = status.pc ++ (int_of_byte rel) }
     
    10151046         status
    10161047 | JNB ((`BIT b1), (`REL rel)) ->
    1017      let val_bit = fetch_arg1 status (`BIT b1) in
     1048     let val_bit = get_arg_1 status (`BIT b1) in
    10181049       if val_bit = false then
    10191050         { status with pc = status.pc ++ (int_of_byte rel) }
     
    10211052         status
    10221053 | JBC ((`BIT b1), (`REL rel)) ->
    1023     let val_bit = fetch_arg1 status (`BIT b1) in
     1054    let val_bit = get_arg_1 status (`BIT b1) in
    10241055    let new_status = set_arg1 status false (`BIT b1) in
    10251056       if val_bit = true then
     
    10941125       status
    10951126 | CJNE ((`U1 (`A, ag)), `REL rel) ->
    1096      let ag_val = fetch_arg8 status ag in
     1127     let ag_val = get_arg_8 status ag in
    10971128     let acc_val = status.acc in
    10981129     let (b1,b2,b3,b4),n2 = status.psw in
     
    11031134         { status with psw = (new_carry, b2, b3, b4),n2 }
    11041135 | CJNE ((`U2 (ag, `DATA d)), `REL rel) ->
    1105      let ag_val = fetch_arg8 status ag in
     1136     let ag_val = get_arg_8 status ag in
    11061137     let (b1,b2,b3,b4),n2 = status.psw in
    11071138     let new_carry = ag_val < d in
     
    11111142         { status with psw = (new_carry, b2, b3, b4),n2 }
    11121143 | DJNZ (ag, (`REL rel)) ->
    1113      let ag_val = fetch_arg8 status ag in
     1144     let ag_val = get_arg_8 status ag in
    11141145     let new_ag_val = byte_of_int ((int_of_byte ag_val) - 1) in
    11151146       if ag_val <> ((false,false,false,false),(false,false,false,false)) then
  • Deliverables/D4.1/BitVectors.ml

    r89 r90  
    137137        pad diff big_list
    138138   
     139let zero size = pad (size_lookup size) []
  • Deliverables/D4.1/BitVectors.mli

    r89 r90  
    2525
    2626val int_of_vect: 'a vect -> int
    27 val vect_of_int: int -> [`Four | `Seven | `Eight | `Eleven | `Sixteen ] -> [`Four | `Seven | `Eight | `Eleven | `Sixteen ] vect
     27val vect_of_int: int -> [< `Four | `Seven | `Eight | `Eleven | `Sixteen ] -> [`Four | `Seven | `Eight | `Eleven | `Sixteen ] vect
    2828
    2929val (-&-): 'a vect -> 'a vect -> 'a vect
     
    3838val string_of_vect: 'a vect -> string
    3939
     40val zero: [< `Four | `Seven | `Eight | `Eleven | `Sixteen ] -> [< `Four | `Seven | `Eight | `Eleven | `Sixteen ] vect
     41
    4042val half_add: 'a vect -> 'a vect -> bit * 'a vect
    4143val full_add: 'a vect -> 'a vect -> bit -> bit * 'a vect
  • Deliverables/D4.1/physical.ml

    r88 r90  
    1 open Bit_vectors
     1open BitVectors;;
    22
    33exception Byte7_conversion
     
    1414
    1515let add8_with_c b1 b2 c =
    16  let n1 = int_of_byte b1 in
    17  let n2 = int_of_byte b2 in
    18  let c = int_of_bit c in
     16 let n1 = int_of_vect b1 in
     17 let n2 = int_of_vect b2 in
     18 let c = int_of_vect c in
    1919 let res = n1 + n2 + c in
    2020 let ac = n1 mod 16 + n2 mod 16 + c >= 16 in
     
    2222 let res,c = res mod 256, res >= 256 in
    2323 let ov = c <> c6 in
    24   byte_of_int res,c,ac,ov
     24   vect_of_int res,c,ac,ov
    2525;;
    2626
    2727let subb8_with_c b1 b2 c =
    28  let n1 = int_of_byte b1 in
    29  let n2 = int_of_byte b2 in
    30  let c = int_of_bit c in
     28 let n1 = int_of_vect b1 in
     29 let n2 = int_of_vect b2 in
     30 let c = int_of_vect c in
    3131 let res = n1 - n2 - c in
    3232 let ac = n1 mod 16 - n2 mod 16 - c < 0 in
     
    3636  else n1 + 256 - n2 - c, true in
    3737 let ov = c <> c6 in
    38   byte_of_int res,c,ac,ov
     38  (vect_of_int res `Eight,c,ac,ov)
    3939;;
    4040
    4141let dec b =
    42  let res = int_of_byte b - 1 in
    43   if res < 0 then byte_of_int 255
    44   else byte_of_int res
     42 let res = int_of_vect b - 1 in
     43  if res < 0 then vect_of_int 255 `Eight
     44  else vect_of_int res `Eight
    4545;;
    4646
    4747let inc b =
    48  let res = int_of_byte b + 1 in
    49   if res > 255 then byte_of_int 0
    50   else byte_of_int res
     48 let res = int_of_vect b + 1 in
     49  if res > 255 then vect_of_int 0 `Eight
     50  else vect_of_int res `Eight
    5151;;
    5252
Note: See TracChangeset for help on using the changeset viewer.