put arm tests in arm module

This commit is contained in:
Torsten Ruger 2017-01-03 22:37:55 +02:00
parent a14a0de9d1
commit da58ce30e3
7 changed files with 307 additions and 293 deletions

View File

@ -4,23 +4,25 @@ require_relative "../helper"
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp # one instruction at a time, reverse testing from objdump --demangle -Sfghxp
# tests are named as per assembler code, ie test_mov testing mov instruction # tests are named as per assembler code, ie test_mov testing mov instruction
module ArmHelper module Arm
def setup module ArmHelper
@machine = Arm::ArmMachine def setup
end @machine = Arm::ArmMachine
end
# code is what the generator spits out, at least one instruction worth (.first) # code is what the generator spits out, at least one instruction worth (.first)
# the op code is wat was witten as assembler in the first place and the binary result # the op code is wat was witten as assembler in the first place and the binary result
def assert_code code , op , should def assert_code code , op , should
assert_equal op , code.opcode assert_equal op , code.opcode
io = StringIO.new io = StringIO.new
code.assemble(io) code.assemble(io)
binary = io.string binary = io.string
assert_equal should.length , binary.length , "code length wrong for #{code.inspect}" assert_equal should.length , binary.length , "code length wrong for #{code.inspect}"
index = 0 index = 0
binary.each_byte do |byte | binary.each_byte do |byte |
assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}" assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}"
index += 1 index += 1
end
end end
end end
end end

View File

@ -1,26 +1,28 @@
require_relative 'helper' require_relative 'helper'
class TestControl < MiniTest::Test module Arm
include ArmHelper class TestControl < MiniTest::Test
include ArmHelper
def test_b def test_b
# the address is what an assembler calculates (a signed number for the amount of instructions), # 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 # 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) # so the cpu adds the value*4 and starts loading that (load, decode, execute)
code = @machine.b( -4 ) #this jumps to the next instruction code = @machine.b( -4 ) #this jumps to the next instruction
assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
end end
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here) def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
code = @machine.call( -4 ,{} )#this jumps to the next instruction code = @machine.call( -4 ,{} )#this jumps to the next instruction
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
end end
def test_swi def test_swi
code = @machine.swi( 0x05 ) code = @machine.swi( 0x05 )
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05
end end
def test_swi_neg def test_swi_neg
assert_raises(RuntimeError) do assert_raises(RuntimeError) do
assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef] assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef]
end
end end
end end
end end

View File

@ -1,30 +1,32 @@
require_relative 'helper' require_relative 'helper'
class TestArmAsm < MiniTest::Test module Arm
include ArmHelper class TestArmAsm < MiniTest::Test
include ArmHelper
def test_cmn def test_cmn
code = @machine.cmn :r1 , :r2 code = @machine.cmn :r1 , :r2
assert_code code , :cmn , [0x02,0x00,0x71,0xe1] #e1 71 00 02 assert_code code , :cmn , [0x02,0x00,0x71,0xe1] #e1 71 00 02
end end
def test_cmp def test_cmp
code = @machine.cmp :r1 , :r2 code = @machine.cmp :r1 , :r2
assert_code code , :cmp , [0x02,0x00,0x51,0xe1] #e1 51 00 02 assert_code code , :cmp , [0x02,0x00,0x51,0xe1] #e1 51 00 02
end end
def test_teq def test_teq
code = @machine.teq :r1 , :r2 code = @machine.teq :r1 , :r2
assert_code code , :teq , [0x02,0x00,0x31,0xe1] #e1 31 00 02 assert_code code , :teq , [0x02,0x00,0x31,0xe1] #e1 31 00 02
end end
def test_tst def test_tst
code = @machine.tst :r1 , :r2 code = @machine.tst :r1 , :r2
assert_code code , :tst , [0x02,0x00,0x11,0xe1] #e1 11 00 02 assert_code code , :tst , [0x02,0x00,0x11,0xe1] #e1 11 00 02
end end
def test_tst2 def test_tst2
code = @machine.tst :r1 , :r1 code = @machine.tst :r1 , :r1
assert_code code , :tst , [0x01,0x00,0x11,0xe1] #e1 11 00 01 assert_code code , :tst , [0x01,0x00,0x11,0xe1] #e1 11 00 01
end end
def test_tst3 def test_tst3
code = @machine.tst :r2 , :r2 code = @machine.tst :r2 , :r2
assert_code code , :tst , [0x02,0x00,0x12,0xe1] #e1 12 00 02 assert_code code , :tst , [0x02,0x00,0x12,0xe1] #e1 12 00 02
end
end end
end end

View File

@ -1,94 +1,96 @@
require_relative 'helper' require_relative 'helper'
class TestLogic < MiniTest::Test module Arm
include ArmHelper class TestLogic < MiniTest::Test
include ArmHelper
def test_mul1 def test_mul1
code = @machine.mul( :r0 , :r1 , :r2) code = @machine.mul( :r0 , :r1 , :r2)
assert_code code , :mul , [0x91,0x02,0x10,0xe0] #e0 10 02 91 assert_code code , :mul , [0x91,0x02,0x10,0xe0] #e0 10 02 91
end end
def test_mul2 def test_mul2
code = @machine.mul( :r1 , :r2 , :r3) code = @machine.mul( :r1 , :r2 , :r3)
assert_code code , :mul , [0x92,0x03,0x11,0xe0] #e0 11 03 92 assert_code code , :mul , [0x92,0x03,0x11,0xe0] #e0 11 03 92
end end
def test_mul3 def test_mul3
code = @machine.mul( :r2 , :r3 , :r4) code = @machine.mul( :r2 , :r3 , :r4)
assert_code code , :mul , [0x93,0x04,0x12,0xe0] #e0 12 04 93 assert_code code , :mul , [0x93,0x04,0x12,0xe0] #e0 12 04 93
end end
def test_and def test_and
code = @machine.and( :r1 , :r2 , :r3) code = @machine.and( :r1 , :r2 , :r3)
assert_code code , :and , [0x03,0x10,0x12,0xe0] #e0 12 10 03 assert_code code , :and , [0x03,0x10,0x12,0xe0] #e0 12 10 03
end end
def test_bic def test_bic
code = @machine.bic :r2 , :r2 , :r3 code = @machine.bic :r2 , :r2 , :r3
assert_code code , :bic , [0x03,0x20,0xd2,0xe1] #e3 d2 20 44 assert_code code , :bic , [0x03,0x20,0xd2,0xe1] #e3 d2 20 44
end end
def test_eor def test_eor
code = @machine.eor :r2 , :r2 , :r3 code = @machine.eor :r2 , :r2 , :r3
assert_code code , :eor , [0x03,0x20,0x32,0xe0] #e0 32 20 03 assert_code code , :eor , [0x03,0x20,0x32,0xe0] #e0 32 20 03
end end
def test_rsb def test_rsb
code = @machine.rsb :r1 , :r2 , :r3 code = @machine.rsb :r1 , :r2 , :r3
assert_code code , :rsb , [0x03,0x10,0x72,0xe0]#e0 72 10 03 assert_code code , :rsb , [0x03,0x10,0x72,0xe0]#e0 72 10 03
end end
def test_rsc def test_rsc
code = @machine.rsc :r2 , :r3 , :r4 code = @machine.rsc :r2 , :r3 , :r4
assert_code code , :rsc , [0x04,0x20,0xf3,0xe0]#e0 f3 20 04 assert_code code , :rsc , [0x04,0x20,0xf3,0xe0]#e0 f3 20 04
end end
def test_sbc def test_sbc
code = @machine.sbc :r3, :r4 , :r5 code = @machine.sbc :r3, :r4 , :r5
assert_code code , :sbc , [0x05,0x30,0xd4,0xe0]#e0 d4 30 05 assert_code code , :sbc , [0x05,0x30,0xd4,0xe0]#e0 d4 30 05
end end
def test_sub def test_sub
code = @machine.sub :r2, :r0, 1 code = @machine.sub :r2, :r0, 1
assert_code code, :sub , [0x01,0x20,0x50,0xe2] #e2 50 20 01 assert_code code, :sub , [0x01,0x20,0x50,0xe2] #e2 50 20 01
end end
def test_subs def test_subs
code = @machine.sub :r2, :r2, 1 , update_status: 1 code = @machine.sub :r2, :r2, 1 , update_status: 1
assert_code code, :sub , [0x01,0x20,0x52,0xe2] #e2 52 20 01 assert_code code, :sub , [0x01,0x20,0x52,0xe2] #e2 52 20 01
end end
def test_orr def test_orr
code = @machine.orr :r2 , :r2 , :r3 code = @machine.orr :r2 , :r2 , :r3
assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03 assert_code code , :orr , [0x03,0x20,0x92,0xe1] #e1 92 20 03
end end
def test_adc def test_adc
code = @machine.adc :r1, :r3, :r5 code = @machine.adc :r1, :r3, :r5
assert_code code , :adc , [0x05,0x10,0xb3,0xe0] #e0 b3 10 05 assert_code code , :adc , [0x05,0x10,0xb3,0xe0] #e0 b3 10 05
end end
def test_add def test_add
code = @machine.add :r1 , :r1, :r3 code = @machine.add :r1 , :r1, :r3
assert_code code , :add , [0x03,0x10,0x91,0xe0] #e0 91 10 03 assert_code code , :add , [0x03,0x10,0x91,0xe0] #e0 91 10 03
end end
def test_add_const def test_add_const
code = @machine.add :r1 , :r1, 0x22 code = @machine.add :r1 , :r1, 0x22
assert_code code , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22 assert_code code , :add , [0x22,0x10,0x91,0xe2] #e2 91 10 22
end end
def test_add_const_pc def test_add_const_pc
code = @machine.add :r1 , :pc, 0x22 code = @machine.add :r1 , :pc, 0x22
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
end end
def test_add_const_shift def test_add_const_shift
code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8) code = @machine.add( :r1 , :r1 , 0x22 , shift_lsr: 8)
assert_code code , :add , [0x22,0x14,0x91,0xe2] #e2 91 14 23 assert_code code , :add , [0x22,0x14,0x91,0xe2] #e2 91 14 23
end end
def test_add_lst def test_add_lst
code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8) code = @machine.add( :r1 , :r2 , :r3 , shift_lsr: 8)
assert_code code , :add , [0x23,0x14,0x92,0xe0] #e0 92 14 23 assert_code code , :add , [0x23,0x14,0x92,0xe0] #e0 92 14 23
end end
def test_big_add def test_big_add
code = @machine.add :r1 , :r1, 0x220 code = @machine.add :r1 , :r1, 0x220
assert_code code , :add , [0x22,0x1e,0x91,0xe2] #e2 91 1e 22 assert_code code , :add , [0x22,0x1e,0x91,0xe2] #e2 91 1e 22
end end
def label pos = 0x22 def label pos = 0x22
l = Register.label("some" , "Label") l = Register.label("some" , "Label")
l.set_position pos l.set_position pos
l l
end end
def pest_move_object def pest_move_object
code = @machine.add( :r1 , label) code = @machine.add( :r1 , label)
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22 assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
end end
end
end end

View File

@ -1,74 +1,76 @@
require_relative 'helper' require_relative 'helper'
class TestMemory < MiniTest::Test module Arm
include ArmHelper class TestMemory < MiniTest::Test
include ArmHelper
def test_ldr def test_ldr
code = @machine.ldr :r0, :r0 code = @machine.ldr :r0, :r0
assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00 assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00
end end
def test_ldr_const_offset def test_ldr_const_offset
code = @machine.ldr :r0, :r0 , 4 code = @machine.ldr :r0, :r0 , 4
assert_code code, :ldr , [0x04,0x00,0x90,0xe5] #e5 90 00 04 assert_code code, :ldr , [0x04,0x00,0x90,0xe5] #e5 90 00 04
end end
def test_ldr_reg_offset def test_ldr_reg_offset
code = @machine.ldr :r3, :r4 , :r5 code = @machine.ldr :r3, :r4 , :r5
assert_code code, :ldr , [0x05,0x30,0x94,0xe7] #e7 94 30 05 assert_code code, :ldr , [0x05,0x30,0x94,0xe7] #e7 94 30 05
end end
def test_ldr_reg_shift2 def test_ldr_reg_shift2
code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 2 code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 2
assert_code code, :ldr , [0x05,0x31,0x94,0xe7] #e7 94 31 05 assert_code code, :ldr , [0x05,0x31,0x94,0xe7] #e7 94 31 05
end end
def test_ldr_reg_shift3 def test_ldr_reg_shift3
code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 3 code = @machine.ldr :r3, :r4 , :r5 , :shift_lsl => 3
assert_code code, :ldr , [0x85,0x31,0x94,0xe7] #e7 94 31 85 assert_code code, :ldr , [0x85,0x31,0x94,0xe7] #e7 94 31 85
end end
def test_ldrb def test_ldrb
code = @machine.ldrb :r0, :r0 code = @machine.ldrb :r0, :r0
assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00 assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00
end end
def test_ldrb_const def test_ldrb_const
code = @machine.ldrb :r0, :r0 , 12 code = @machine.ldrb :r0, :r0 , 12
assert_code code, :ldrb , [0x0c,0x00,0xd0,0xe5] #e5 d0 00 0c assert_code code, :ldrb , [0x0c,0x00,0xd0,0xe5] #e5 d0 00 0c
end end
def test_ldrb_reg_offset def test_ldrb_reg_offset
code = @machine.ldrb :r0, :r1 , :r2 code = @machine.ldrb :r0, :r1 , :r2
assert_code code, :ldrb , [0x02,0x00,0xd1,0xe7] #e7 d1 00 02 assert_code code, :ldrb , [0x02,0x00,0xd1,0xe7] #e7 d1 00 02
end end
def test_str def test_str
code = @machine.str :r0, :r1 code = @machine.str :r0, :r1
assert_code code, :str , [0x00,0x00,0x81,0xe5] #e5 81 00 00 assert_code code, :str , [0x00,0x00,0x81,0xe5] #e5 81 00 00
end end
def test_str_const_offset def test_str_const_offset
code = @machine.str :r1, :r2 , 4 code = @machine.str :r1, :r2 , 4
assert_code code, :str , [0x04,0x10,0x82,0xe5] #e5 82 10 04 assert_code code, :str , [0x04,0x10,0x82,0xe5] #e5 82 10 04
end end
def test_str_reg_offset def test_str_reg_offset
code = @machine.str :r3, :r4 , :r5 code = @machine.str :r3, :r4 , :r5
assert_code code, :str , [0x05,0x30,0x84,0xe7] #e7 84 30 05 assert_code code, :str , [0x05,0x30,0x84,0xe7] #e7 84 30 05
end end
def test_str_reg_shift def test_str_reg_shift
code = @machine.str :r3, :r4 , :r5 , :shift_lsl => 2 code = @machine.str :r3, :r4 , :r5 , :shift_lsl => 2
assert_code code, :str , [0x05,0x31,0x84,0xe7] #e7 84 31 05 assert_code code, :str , [0x05,0x31,0x84,0xe7] #e7 84 31 05
end end
def test_strb_inc #THIS IS BROKEN, but so is gnu as, as it produces same output for ! or not def test_strb_inc #THIS IS BROKEN, but so is gnu as, as it produces same output for ! or not
code = @machine.strb :r0, :r2 , 1 , pre_post_index: 1 # pre_post_index is autoinc (r2 here) code = @machine.strb :r0, :r2 , 1 , pre_post_index: 1 # pre_post_index is autoinc (r2 here)
assert_code code, :strb , [0x01,0x00,0xc2,0xe5] #e5 e2 00 01 assert_code code, :strb , [0x01,0x00,0xc2,0xe5] #e5 e2 00 01
end end
def test_strb def test_strb
code = @machine.strb :r0, :r0 code = @machine.strb :r0, :r0
assert_code code, :strb , [0x00,0x00,0xc0,0xe5] #e5 c0 00 00 assert_code code, :strb , [0x00,0x00,0xc0,0xe5] #e5 c0 00 00
end end
def test_strb_const def test_strb_const
code = @machine.strb :r1, :r2 , 4 code = @machine.strb :r1, :r2 , 4
assert_code code, :strb , [0x04,0x10,0xc2,0xe5] #e5 c2 10 04 assert_code code, :strb , [0x04,0x10,0xc2,0xe5] #e5 c2 10 04
end end
def test_strb_reg_offset def test_strb_reg_offset
code = @machine.strb :r1, :r2 , :r3 code = @machine.strb :r1, :r2 , :r3
assert_code code, :strb , [0x03,0x10,0xc2,0xe7] #e7 c2 10 03 assert_code code, :strb , [0x03,0x10,0xc2,0xe7] #e7 c2 10 03
end
end end
end end

View File

@ -1,62 +1,64 @@
require_relative 'helper' require_relative 'helper'
class TestMoves < MiniTest::Test module Arm
include ArmHelper class TestMoves < MiniTest::Test
include ArmHelper
def test_mov def test_mov
code = @machine.mov :r1, 5 code = @machine.mov :r1, 5
assert_code code , :mov , [0x05,0x10,0xb0,0xe3] #e3 b0 10 05 assert_code code , :mov , [0x05,0x10,0xb0,0xe3] #e3 b0 10 05
end end
def test_mov_pc def test_mov_pc
code = @machine.mov :pc, 5 code = @machine.mov :pc, 5
assert_code code , :mov , [0x05,0xf0,0xb0,0xe3] #e3 b0 f0 06 assert_code code , :mov , [0x05,0xf0,0xb0,0xe3] #e3 b0 f0 06
end end
def test_mov_max_128 def test_mov_max_128
code = @machine.mov :r1, 128 code = @machine.mov :r1, 128
assert_code code , :mov , [0x80,0x10,0xb0,0xe3] #e3 b0 10 80 assert_code code , :mov , [0x80,0x10,0xb0,0xe3] #e3 b0 10 80
end end
def test_mov_256 def test_mov_256
code = @machine.mov :r1, 256 code = @machine.mov :r1, 256
assert_code code , :mov , [0x01,0x1c,0xb0,0xe3] #e3 b0 1c 01 assert_code code , :mov , [0x01,0x1c,0xb0,0xe3] #e3 b0 1c 01
end end
def test_mov_big def test_mov_big
code = @machine.mov :r0, 0x222 # is not 8 bit and can't be rotated by the arm system in one instruction code = @machine.mov :r0, 0x222 # is not 8 bit and can't be rotated by the arm system in one instruction
code.set_position(0) code.set_position(0)
begin # mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22 begin # mov 512(0x200) = e3 a0 0c 02 add 34(0x22) = e2 90 00 22
assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3 , 0x22,0x00,0x90,0xe2] assert_code code , :mov , [ 0x02,0x0c,0xb0,0xe3 , 0x22,0x00,0x90,0xe2]
rescue Register::LinkException rescue Register::LinkException
retry retry
end
end
def test_mvn
code = @machine.mvn :r1, 5
assert_code code , :mvn , [0x05,0x10,0xf0,0xe3] #e3 f0 10 05
end end
end
def test_mvn
code = @machine.mvn :r1, 5
assert_code code , :mvn , [0x05,0x10,0xf0,0xe3] #e3 f0 10 05
end
def test_shiftr1 def test_shiftr1
code = @machine.mov :r1, :r2 , :shift_asr => Register::RegisterValue.new(:r3 , :Integer) code = @machine.mov :r1, :r2 , :shift_asr => Register::RegisterValue.new(:r3 , :Integer)
assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52 assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52
end end
def test_shiftr2 def test_shiftr2
code = @machine.mov :r2, :r3 , :shift_asr => Register::RegisterValue.new(:r4 , :Integer) code = @machine.mov :r2, :r3 , :shift_asr => Register::RegisterValue.new(:r4 , :Integer)
assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53 assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53
end end
def test_shiftr3 def test_shiftr3
code = @machine.mov :r3, :r4 , :shift_asr => Register::RegisterValue.new(:r5 , :Integer) code = @machine.mov :r3, :r4 , :shift_asr => Register::RegisterValue.new(:r5 , :Integer)
assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54 assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54
end end
def test_shiftl1 def test_shiftl1
code = @machine.mov :r1, :r2 , :shift_lsr => Register::RegisterValue.new(:r3 , :Integer) code = @machine.mov :r1, :r2 , :shift_lsr => Register::RegisterValue.new(:r3 , :Integer)
assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32 assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32
end end
def test_shiftl2 def test_shiftl2
code = @machine.mov :r2, :r3 , :shift_lsr => Register::RegisterValue.new(:r4 , :Integer) code = @machine.mov :r2, :r3 , :shift_lsr => Register::RegisterValue.new(:r4 , :Integer)
assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33 assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33
end end
def test_shiftl3 def test_shiftl3
code = @machine.mov :r3, :r4 , :shift_lsr => Register::RegisterValue.new(:r5 , :Integer) code = @machine.mov :r3, :r4 , :shift_lsr => Register::RegisterValue.new(:r5 , :Integer)
assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34 assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34
end end
end
end end

View File

@ -1,31 +1,33 @@
require_relative 'helper' require_relative 'helper'
class TestStack < MiniTest::Test module Arm
include ArmHelper class TestStack < MiniTest::Test
include ArmHelper
def test_push
code = @machine.push [:lr]
assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00
end
def test_push_three
code = @machine.push [:r0,:r1,:lr]
assert_code code , :push , [0x03,0x40,0x2d,0xe9] #e9 2d 40 03
end
def test_push_no_link
code = @machine.push [:r0,:r1,:r2 ,:r3,:r4,:r5]
assert_code code , :push , [0x3f,0x00,0x2d,0xe9] #e9 2d 00 3f
end
def test_pop
code = @machine.pop [:pc]
assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00
end
def test_pop_three
code = @machine.pop [:r0,:r1,:pc]
assert_code code , :pop , [0x03,0x80,0xbd,0xe8] #e8 bd 80 03
end
def test_pop_no_pc
code = @machine.pop [:r0,:r1,:r2 ,:r3,:r4,:r5]
assert_code code , :pop , [0x3f,0x00,0xbd,0xe8] #e8 bd 00 3f
end
def test_push
code = @machine.push [:lr]
assert_code code , :push , [0x00,0x40,0x2d,0xe9] #e9 2d 40 00
end end
def test_push_three
code = @machine.push [:r0,:r1,:lr]
assert_code code , :push , [0x03,0x40,0x2d,0xe9] #e9 2d 40 03
end
def test_push_no_link
code = @machine.push [:r0,:r1,:r2 ,:r3,:r4,:r5]
assert_code code , :push , [0x3f,0x00,0x2d,0xe9] #e9 2d 00 3f
end
def test_pop
code = @machine.pop [:pc]
assert_code code , :pop , [0x00,0x80,0xbd,0xe8] #e8 bd 80 00
end
def test_pop_three
code = @machine.pop [:r0,:r1,:pc]
assert_code code , :pop , [0x03,0x80,0xbd,0xe8] #e8 bd 80 03
end
def test_pop_no_pc
code = @machine.pop [:r0,:r1,:r2 ,:r3,:r4,:r5]
assert_code code , :pop , [0x3f,0x00,0xbd,0xe8] #e8 bd 00 3f
end
end end