2014-04-14 20:53:29 +02:00
|
|
|
require_relative 'helper'
|
2014-04-14 14:58:59 +02:00
|
|
|
|
2014-04-17 13:43:52 +02:00
|
|
|
class TestArmAsm < MiniTest::Test
|
2014-05-16 16:30:26 +02:00
|
|
|
include ArmHelper
|
2014-04-14 20:53:29 +02:00
|
|
|
|
2014-04-19 18:34:04 +02:00
|
|
|
def test_b
|
|
|
|
# the address is what an assembler calculates (a signed number for the amount of instructions),
|
|
|
|
# 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)
|
2014-05-15 18:41:51 +02:00
|
|
|
code = @machine.b -4 , {} #this jumps to the next instruction
|
2014-04-19 18:34:04 +02:00
|
|
|
assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
|
|
|
|
end
|
2014-05-14 09:47:30 +02:00
|
|
|
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
|
2014-05-15 18:41:51 +02:00
|
|
|
code = @machine.call -4 ,{} #this jumps to the next instruction
|
2014-05-14 09:47:30 +02:00
|
|
|
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
|
2014-04-19 18:34:04 +02:00
|
|
|
end
|
2014-04-17 19:24:37 +02:00
|
|
|
def test_bic
|
2014-05-16 10:27:30 +02:00
|
|
|
code = @machine.bic :r2 , left: :r2 , right: :r3
|
2014-04-18 14:49:23 +02:00
|
|
|
assert_code code , :bic , [0x03,0x20,0xc2,0xe1] #e3 c2 20 44
|
|
|
|
end
|
2014-04-20 22:48:04 +02:00
|
|
|
def test_push
|
2014-05-15 18:41:51 +02:00
|
|
|
code = @machine.push [:lr] , {}
|
2014-04-20 22:48:04 +02:00
|
|
|
assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00
|
|
|
|
end
|
|
|
|
def test_pop
|
2014-05-15 18:41:51 +02:00
|
|
|
code = @machine.pop [:pc] , {}
|
2014-04-20 22:48:04 +02:00
|
|
|
assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00
|
|
|
|
end
|
2014-04-18 14:49:23 +02:00
|
|
|
def test_rsb
|
2014-05-16 10:27:30 +02:00
|
|
|
code = @machine.rsb :r1 , left: :r2 , right: :r3
|
2014-04-18 14:49:23 +02:00
|
|
|
assert_code code , :rsb , [0x03,0x10,0x62,0xe0]#e0 62 10 03
|
|
|
|
end
|
|
|
|
def test_rsc
|
2014-05-16 10:27:30 +02:00
|
|
|
code = @machine.rsc :r2 , left: :r3 , right: :r4
|
2014-04-18 14:49:23 +02:00
|
|
|
assert_code code , :rsc , [0x04,0x20,0xe3,0xe0]#e0 e3 20 04
|
|
|
|
end
|
|
|
|
def test_sbc
|
2014-05-16 10:27:30 +02:00
|
|
|
code = @machine.sbc :r3, left: :r4 , right: :r5
|
2014-04-18 14:49:23 +02:00
|
|
|
assert_code code , :sbc , [0x05,0x30,0xc4,0xe0]#e0 c4 30 05
|
|
|
|
end
|
|
|
|
def test_swi
|
2014-05-18 10:11:26 +02:00
|
|
|
code = @machine.swi 0x05
|
2014-04-18 14:49:23 +02:00
|
|
|
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05
|
2014-04-17 19:24:37 +02:00
|
|
|
end
|
2014-04-14 14:58:59 +02:00
|
|
|
end
|