Skip to content

Commit

Permalink
Added MDI instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
dparnell committed May 28, 2012
1 parent 49628e1 commit c7cbf61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/dcpu16_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion test/dcpu16_core_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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.