diff --git a/test/arm/arm-helper.rb b/test/arm/arm-helper.rb index 985d7774..ffd0b533 100644 --- a/test/arm/arm-helper.rb +++ b/test/arm/arm-helper.rb @@ -17,9 +17,9 @@ module ArmHelper def assert_code code , op , should assert_equal op , code.opcode io = StringIO.new - code.assemble(io,nil) + code.assemble(io) binary = io.string - assert_equal 4 , binary.length , "code length wrong for #{code.inspect}" + assert_equal should.length , binary.length , "code length wrong for #{code.inspect}" index = 0 binary.each_byte do |byte | assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}" diff --git a/test/arm/test_add.rb b/test/arm/test_add.rb new file mode 100644 index 00000000..8f750923 --- /dev/null +++ b/test/arm/test_add.rb @@ -0,0 +1,30 @@ +require_relative 'arm-helper' + +class TestAdd < MiniTest::Test + include ArmHelper + + def test_adc + code = @machine.adc :r1, :r3, :r5 + assert_code code , :adc , [0x05,0x10,0xa3,0xe0] #e0 a3 10 05 + end + def test_add + code = @machine.add :r1 , :r1, :r3 + assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03 + end + def test_add_const + code = @machine.add :r1 , :r1, 0x22 + assert_code code , :add , [0x22,0x10,0x81,0xe2] #e2 81 10 22 + end + def test_add_const_shift_lst + code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8) + assert_code code , :add , [0x22,0x14,0x81,0xe2] #e2 81 14 23 + end + def test_add_lst + code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8) + assert_code code , :add , [0x23,0x14,0x82,0xe0] #e0 82 14 23 + end + def test_big_add + code = @machine.add :r1 , :r1, 0x220 + assert_code code , :add , [0x20,0x12,0x81,0xe2] #e2 81 12 20 + end +end \ No newline at end of file diff --git a/test/arm/test_all.rb b/test/arm/test_all.rb index 31a27379..8321fda1 100644 --- a/test/arm/test_all.rb +++ b/test/arm/test_all.rb @@ -1,6 +1,7 @@ require_relative "test_stack" require_relative "test_control" require_relative "test_logic" +require_relative "test_add" require_relative "test_move" require_relative "test_memory" require_relative "test_compare" diff --git a/test/arm/test_logic.rb b/test/arm/test_logic.rb index 1ec9d727..0173fe6e 100644 --- a/test/arm/test_logic.rb +++ b/test/arm/test_logic.rb @@ -3,18 +3,6 @@ require_relative 'arm-helper' class TestLogic < MiniTest::Test include ArmHelper - def test_adc - code = @machine.adc :r1, :r3, :r5 - assert_code code , :adc , [0x05,0x10,0xa3,0xe0] #e0 a3 10 05 - end - def test_add - code = @machine.add :r1 , :r1, :r3 - assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03 - end - def test_add_lst - code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8) - assert_code code , :add , [0x23,0x14,0x82,0xe0] #e0 82 14 23 - end def test_and # inst eval doesn't really work with and code = @machine.and( :r1 , :r2 , :r3) assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03 diff --git a/test/arm/test_move.rb b/test/arm/test_move.rb index 8cf38d29..d18330f2 100644 --- a/test/arm/test_move.rb +++ b/test/arm/test_move.rb @@ -7,6 +7,19 @@ class TestMoves < MiniTest::Test code = @machine.mov :r0, 5 assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05 end + def test_mov_pc + code = @machine.mov :pc, 6 + assert_code code , :mov , [0x06,0xf0,0xa0,0xe3] #e3 a0 f0 06 + end + def test_mov_big + code = @machine.mov :r0, 0x222 + code.set_position(0) + begin #TODO use compiler to confirm codes here: this is just what passes + assert_code code , :mov , [ 0x02,0x00,0xa0,0xe3 , 0xff,0x04,0x80,0xe2] + rescue Register::LinkException + retry + end + end def test_mvn code = @machine.mvn :r1, 5 assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05