Changeset 112


Ignore:
Timestamp:
Sep 23, 2010, 10:36:49 AM (9 years ago)
Author:
mulligan
Message:

PUSH, POP, XCH and XCHD refactored and tidied.

File:
1 edited

Legend:

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

    r111 r112  
    993993     let lookup = WordMap.find addr status.code_memory in
    994994       { status with acc = lookup }
    995 (*
    996995 (* data transfer *)
    997996(*
     
    999998            [ indirect | indirect_dptr ] * acc) union2
    1000999*)
    1001  | SETB a -> set_arg1 status true a
    1002  | PUSH (`DIRECT b) ->
    1003      let status = { status with pc = status.pc ++ 1 } in
    1004      let memory = Byte7Map.add (byte7_of_byte status.sp) b status.low_internal_ram in
    1005      let status = { status with low_internal_ram = memory } in
    1006        status
    1007  | POP (`DIRECT b) ->
    1008      let contents = Byte7Map.find (byte7_of_byte status.sp) status.low_internal_ram in
    1009      let status = { status with pc = status.pc ++ (-1) } in
    1010      let status = set_arg8 status contents (`DIRECT b) in
    1011        status
    1012  | XCH(`A, arg) ->
    1013      let old_arg = get_arg_8 status arg in
    1014      let old_acc = status.acc in
    1015      let new_status = set_arg8 status old_acc arg in
    1016        { new_status with acc = old_arg }
    1017  | XCHD(`A, (`INDIRECT i)) ->
    1018      let ((a1,a2,a3,a4),(a5,a6,a7,a8)) = get_arg_8 status `A in
    1019      let ((i1,i2,i3,i4),(i5,i6,i7,i8)) = get_arg_8 status (`INDIRECT i) in
    1020      let new_acc_val = ((a1,a2,a3,a4),(i5,i6,i7,i8)) in
    1021      let new_reg_val = ((i1,i2,i3,i4),(a5,a6,a7,a8)) in
    1022      let status = set_arg8 status new_acc_val `A in
    1023      let status = set_arg8 status new_reg_val (`INDIRECT i) in
    1024        status
     1000  | `SETB b -> set_arg1 status true b
     1001  | `PUSH (`DIRECT b) ->
     1002       (* DPM: What happens if we overflow? *)
     1003       let cry,new_sp = half_add status.sp (vect_of_int 1 `Eight) in
     1004       let status = { status with sp = new_sp } in
     1005       let memory = Byte7Map.add (byte7_of_byte status.sp) b status.low_internal_ram in
     1006         { status with low_internal_ram = memory }
     1007  | `POP (`DIRECT b) ->
     1008       let contents = Byte7Map.find (byte7_of_byte status.sp) status.low_internal_ram in
     1009       let new_sp,_,_,_ = subb8_with_c status.sp (vect_of_int 1 `Eight) false in
     1010       let status = { status with sp = new_sp } in
     1011       let status = set_arg8 status contents (`DIRECT b) in
     1012         status
     1013  | `XCH(`A, arg) ->
     1014      let old_arg = get_arg_8 status arg in
     1015      let old_acc = status.acc in
     1016      let status = set_arg8 status old_acc arg in
     1017        { status with acc = old_arg }
     1018  | `XCHD(`A, (`INDIRECT i)) ->
     1019      let acc_upper_nibble, acc_lower_nibble = from_byte (get_arg_8 status `A) in
     1020      let ind_upper_nibble, ind_lower_nibble = from_byte (get_arg_8 status (`INDIRECT i)) in
     1021      let new_acc = mk_byte acc_upper_nibble ind_lower_nibble in
     1022      let new_reg = mk_byte ind_upper_nibble acc_lower_nibble in
     1023      let status = { status with acc = new_acc } in
     1024        set_arg8 status new_reg (`INDIRECT i)
     1025(*
    10251026 (* program branching *)
    10261027 | JC (`REL rel) ->
Note: See TracChangeset for help on using the changeset viewer.