Permalink
Browse files

Added MDI instruction

  • Loading branch information...
1 parent 49628e1 commit c7cbf6172b655daa6dbee2b05ac256df35779a53 @dparnell committed May 28, 2012
Showing with 26 additions and 2 deletions.
  1. +8 −1 src/dcpu16_core.erl
  2. +18 −1 test/dcpu16_core_test.erl
View
@@ -368,7 +368,14 @@ execute_micro_op(mod, Cpu, Ram) -> [B, A] = Cpu#cpu.w,
case A of
0 -> { Cpu#cpu{ w = [0] }, Ram, 1 };
_ -> Mod = B rem A,
- { Cpu#cpu{ w = [Mod band 16#ffff] }, Ram, 1 }
+ { Cpu#cpu{ w = [Mod band 16#ffff] }, Ram, 1 }
+ end;
+
+execute_micro_op(mdi, Cpu, Ram) -> [B, A] = Cpu#cpu.w,
+ case A of
+ 0 -> { Cpu#cpu{ w = [0] }, Ram, 1 };
+ _ -> Mod = signed(B) rem signed(A),
+ { Cpu#cpu{ w = [Mod band 16#ffff] }, Ram, 1 }
end;
execute_micro_op(shl, Cpu, Ram) -> [B, A] = Cpu#cpu.w,
View
@@ -394,6 +394,22 @@ simple_asr() ->
dcpu16_core:get_reg(ResultCPU, pc).
+simple_mdi() ->
+ CPU = dcpu16_core:init(),
+
+ ReadyCPU = dcpu16_core:ram(CPU, 0, dcpu16_asm:assemble([
+ { set, a, -7 },
+ { mdi, a, 16 },
+ { ifn, a, -7 },
+ { sub, pc, 1 }, % test failed
+ { sub, pc, 1 } % success
+ ])
+ ),
+
+ ResultCPU = dcpu16_core:cycle(ReadyCPU, 10),
+
+ dcpu16_core:get_reg(ResultCPU, pc).
+
basic_test_() ->
[
?_assertEqual(16#1234, attempt(fun() -> simple_set() end)),
@@ -415,5 +431,6 @@ basic_test_() ->
?_assertEqual(16#0007, attempt(fun() -> simple_xor() end)),
?_assertEqual(16#0006, attempt(fun() -> simple_mli() end)),
?_assertEqual(16#0006, attempt(fun() -> simple_dvi() end)),
- ?_assertEqual(16#0006, attempt(fun() -> simple_asr() end))
+ ?_assertEqual(16#0006, attempt(fun() -> simple_asr() end)),
+ ?_assertEqual(16#0007, attempt(fun() -> simple_mdi() end))
].

0 comments on commit c7cbf61

Please sign in to comment.