2016-12-14 12:43:13 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestControl < MiniTest::Test
|
|
|
|
include ArmHelper
|
|
|
|
|
|
|
|
def test_b
|
2016-12-14 18:06:32 +01:00
|
|
|
# the address is what an assembler calculates (a signed number for the amount of instructions),
|
2016-12-14 12:43:13 +01:00
|
|
|
# ie the relative (to pc) address -8 (pipeline) /4 so save space
|
|
|
|
# so the cpu adds the value*4 and starts loading that (load, decode, execute)
|
2016-12-14 18:06:32 +01:00
|
|
|
code = @machine.b( -4 ) #this jumps to the next instruction
|
2016-12-14 12:43:13 +01:00
|
|
|
assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
|
|
|
|
end
|
|
|
|
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
|
2016-12-14 18:06:32 +01:00
|
|
|
code = @machine.call( -4 ,{} )#this jumps to the next instruction
|
2016-12-14 12:43:13 +01:00
|
|
|
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
|
|
|
|
end
|
|
|
|
def test_swi
|
2016-12-14 18:06:32 +01:00
|
|
|
code = @machine.swi( 0x05 )
|
2016-12-14 12:43:13 +01:00
|
|
|
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05
|
|
|
|
end
|
2016-12-14 18:06:32 +01:00
|
|
|
def test_swi_neg
|
|
|
|
assert_raises(RuntimeError) do
|
|
|
|
assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef]
|
|
|
|
end
|
|
|
|
end
|
2016-12-14 12:43:13 +01:00
|
|
|
end
|