binary_number/2 is more efficient if you strip off 0's first.
This commit is contained in:
parent
67112de952
commit
d488db6abd
|
|
@ -442,6 +442,8 @@ asm(N, vs_offset(Label)) --> instruction_format_F3b(0, vs, Label, N).
|
||||||
asm(_, vs_link(C)) --> instruction_format_F3a(1, vs, C).
|
asm(_, vs_link(C)) --> instruction_format_F3a(1, vs, C).
|
||||||
asm(N, vs_link_offset(Label)) --> instruction_format_F3b(1, vs, Label, N).
|
asm(N, vs_link_offset(Label)) --> instruction_format_F3b(1, vs, Label, N).
|
||||||
|
|
||||||
|
% This is the core of the assembler where the instruction formats are specified.
|
||||||
|
|
||||||
instruction_format_F0(U, A, B, Op, C ) --> [0, 0, U, 0], reg(A), reg(B), operation(Op), skip(12), reg(C).
|
instruction_format_F0(U, A, B, Op, C ) --> [0, 0, U, 0], reg(A), reg(B), operation(Op), skip(12), reg(C).
|
||||||
instruction_format_F1(U, V, A, B, Op, Im) --> [0, 1, U, V], reg(A), reg(B), operation(Op), immediate(Im).
|
instruction_format_F1(U, V, A, B, Op, Im) --> [0, 1, U, V], reg(A), reg(B), operation(Op), immediate(Im).
|
||||||
instruction_format_F2(U, V, A, B, Offset) --> [1, 0, U, V], reg(A), reg(B), offset(Offset).
|
instruction_format_F2(U, V, A, B, Offset) --> [1, 0, U, V], reg(A), reg(B), offset(Offset).
|
||||||
|
|
@ -553,10 +555,8 @@ canonical_binary_number([1|Bits], Number):-
|
||||||
canonical_binary_number(Bits1, Number1),
|
canonical_binary_number(Bits1, Number1),
|
||||||
Number is Number1 + 2 ^ Pow.
|
Number is Number1 + 2 ^ Pow.
|
||||||
|
|
||||||
binary_number(Bits, Number):-
|
binary_number([0|Bits], Number) :- binary_number(Bits, Number).
|
||||||
canonical_binary_number(Bits, Number).
|
binary_number( Bits , Number) :- canonical_binary_number(Bits, Number).
|
||||||
binary_number([0|Bits], Number):-
|
|
||||||
binary_number(Bits, Number).
|
|
||||||
|
|
||||||
|
|
||||||
% Helper code to write the list of bits as a binary file.
|
% Helper code to write the list of bits as a binary file.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue