sim: sim_boolean: handle XORI, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-24 18:17:00 +02:00
parent b3038df02b
commit 84a0e9b226
3 changed files with 21 additions and 0 deletions

View File

@ -43,6 +43,7 @@
, handle_SETZB/4
, handle_SETZM/4
, handle_XOR/4
, handle_XORI/4
]).
-include("sim_core.hrl").
@ -306,6 +307,14 @@ handle_XOR(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_XOR(Core1, Mem1, IR, EA) end)
end.
-spec handle_XORI(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_XORI(Core, Mem, IR, EA) ->
AC = IR band 8#17,
CA = sim_core:get_ac(Core, AC),
Word = CA bxor EA#ea.offset,
sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem).
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -278,6 +278,7 @@ dispatch(Core, Mem, IR, EA) ->
8#426 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA); % SETAM = MOVEM
8#427 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA); % SETAB = MOVEM
8#430 -> sim_boolean:handle_XOR(Core, Mem, IR, EA);
8#431 -> sim_boolean:handle_XORI(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

@ -69,6 +69,7 @@
-define(OP_SETAM, 8#426).
-define(OP_SETAB, 8#426).
-define(OP_XOR, 8#430).
-define(OP_XORI, 8#431).
%% 2.4 Boolean Functions =======================================================
@ -388,6 +389,16 @@ xor_test() ->
[ {#ea{section = 1, offset = 1, islocal = false}, 8#434343} % AC1 = 0,,434343
]).
xori_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070
, {1, 8#101, ?INSN(?OP_XORI, 1, 0, 0, 8#333333)} % 1,,101/ XORI 1,333333
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, 8#434343} % AC1 = 0,,434343
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->