Ignore:
Timestamp:
Sep 30, 2010, 6:46:44 PM (9 years ago)
Author:
mulligan
Message:

Changes made today: we now have an emulator that is able to emulate two
small C programs.

File:
1 edited

Legend:

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

    r145 r147  
    387387       let pc,b1 = next pc in
    388388       let pc,b2 = next pc in
    389          `MOV (`U3 (`DIRECT b1, `DATA b2)), pc, 2
     389         `MOV (`U3 (`DIRECT b1, `DATA b2)), pc, 3
    390390   | (true,true,true,true),(false,true,true,i1) ->
    391391         `MOV (`U2 (`INDIRECT i1, `A)), pc, 1
     
    992992   | `INC ((`A | `REG _ | `DIRECT _ | `INDIRECT _) as d) ->
    993993       let b = get_arg_8 status d in
    994        let cry, res = half_add b (vect_of_int 0 `Eight) in
     994       let cry, res = half_add b (vect_of_int 1 `Eight) in
    995995         set_arg_8 status res d
    996996   | `DEC d ->
     
    11321132  | `JC (`REL rel) ->
    11331133       if get_cy_flag status then
    1134          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1134         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11351135           { status with pc = new_pc }
    11361136       else
     
    11381138  | `JNC (`REL rel) ->
    11391139       if not $ get_cy_flag status then
    1140          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1140         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11411141           { status with pc = new_pc }
    11421142       else
     
    11441144  | `JB (b, (`REL rel)) ->
    11451145       if get_arg_1 status b then
    1146          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1146         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11471147           { status with pc = new_pc }
    11481148       else
     
    11501150  | `JNB (b, (`REL rel)) ->
    11511151       if not $ get_arg_1 status b then
    1152          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1152         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11531153           { status with pc = new_pc }
    11541154       else
     
    11571157       let status = set_arg_1 status false b in
    11581158         if get_arg_1 status b then
    1159            let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1159           let cry, new_pc = half_add status.pc (sign_extension rel) in
    11601160             { status with pc = new_pc }
    11611161         else
     
    11791179         { status with pc = mk_word high_bits low_bits }
    11801180  | `ACALL (`ADDR11 a) ->
    1181        let cry, new_pc = half_add status.pc (vect_of_int 2 `Sixteen) in
    1182        let status = { status with pc = new_pc } in
    11831181       let cry, new_sp = half_add status.sp (vect_of_int 1 `Eight) in
    11841182       let status = { status with sp = new_sp } in
     
    11941192         { status with pc = addr }
    11951193  | `LCALL (`ADDR16 addr) ->
    1196        let cry, new_pc = half_add status.pc (vect_of_int 3 `Sixteen) in
    1197        let status = { status with pc = new_pc } in
    11981194       let cry, new_sp = half_add status.sp (vect_of_int 1 `Eight) in
    11991195       let status = { status with sp = new_sp } in
     
    12051201         { status with pc = addr }
    12061202  | `AJMP (`ADDR11 a) ->
    1207        let cry, new_pc = half_add status.pc (vect_of_int 2 `Sixteen) in
    1208        let status = { status with pc = new_pc } in
    12091203       let pc_upper_byte, pc_lower_byte = from_word status.pc in
    12101204       let n1, n2 = from_byte pc_upper_byte in
     
    12171211       { status with pc = a }
    12181212  | `SJMP (`REL rel) ->
    1219        let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1213       let cry, new_pc = half_add status.pc (sign_extension rel) in
    12201214         { status with pc = new_pc }
    12211215  | `JMP `IND_DPTR ->
     
    12271221  | `JZ (`REL rel) ->
    12281222       if status.acc = zero `Eight then
    1229          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1223         let cry, new_pc = half_add status.pc (sign_extension rel) in
    12301224           { status with pc = new_pc }
    12311225       else
     
    12331227  | `JNZ (`REL rel) ->
    12341228       if status.acc <> zero `Eight then
    1235          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1229         let cry, new_pc = half_add status.pc (sign_extension rel) in
    12361230                           { status with pc = new_pc }
    12371231       else
     
    12401234       let new_carry = status.acc < get_arg_8 status ag in
    12411235         if get_arg_8 status ag <> status.acc then
    1242            let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1236           let cry, new_pc = half_add status.pc (sign_extension rel) in
    12431237           let status = set_flags status new_carry None (get_ov_flag status) in
    12441238             { status with pc = new_pc;  }
     
    12481242     let new_carry = get_arg_8 status ag < d in
    12491243       if get_arg_8 status ag <> d then
    1250          let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1244         let cry, new_pc = half_add status.pc (sign_extension rel) in
    12511245         let status = { status with pc = new_pc } in
    12521246           set_flags status new_carry None (get_ov_flag status)
     
    12571251       let status = set_arg_8 status new_ag ag in
    12581252         if new_ag <> zero `Eight then
    1259            let cry, new_pc = half_add status.pc (mk_word (zero `Eight) rel) in
     1253           let cry, new_pc = half_add status.pc (sign_extension rel) in
    12601254             { status with pc = new_pc }
    12611255         else
Note: See TracChangeset for help on using the changeset viewer.