sim: sim_boolean: handle AND, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-22 21:56:02 +02:00
parent 9c704c9086
commit fe56d76566
3 changed files with 33 additions and 1 deletions

View File

@ -24,7 +24,8 @@
-module(sim_boolean).
-export([ handle_SETZ/4
-export([ handle_AND/4
, handle_SETZ/4
, handle_SETZB/4
, handle_SETZM/4
]).
@ -63,6 +64,22 @@ handle_SETZB(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_SETZB(Core1, Mem1, IR, EA) end)
end.
%% AND - And with AC
-spec handle_AND(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_AND(Core, Mem, IR, EA) ->
case sim_core:c(Core, Mem, EA) of
{ok, CE} ->
AC = IR band 8#17,
CA = sim_core:get_ac(Core, AC),
Word = CE band CA,
sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_AND(Core1, Mem1, IR, EA) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -257,6 +257,7 @@ dispatch(Core, Mem, IR, EA) ->
8#401 -> sim_boolean:handle_SETZ(Core, Mem, IR, EA); % SETZI = SETZ
8#402 -> sim_boolean:handle_SETZM(Core, Mem, IR, EA);
8#403 -> sim_boolean:handle_SETZB(Core, Mem, IR, EA);
8#404 -> sim_boolean:handle_AND(Core, Mem, IR, EA);
_ ->
PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset,
{Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}}

View File

@ -47,6 +47,7 @@
-define(OP_SETZI, 8#401).
-define(OP_SETZM, 8#402).
-define(OP_SETZB, 8#403).
-define(OP_AND, 8#404).
%% 2.4 Boolean Functions =======================================================
@ -94,6 +95,19 @@ setzb_test() ->
, {#ea{section = 1, offset = 1, islocal = false}, 0} % AC1 = 0
]).
%% AND - And with AC
and_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070
, {1, 8#101, ?INSN(?OP_AND, 1, 0, 0, 8#200)} % 1,,101/ AND 1,200
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#200, ?COMMA2(-1, 8#333333)} % 1,,200/ -1,333333
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, 8#303030} % AC1 = 0,,303030
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->