From 2e576740083325c308128adb0e6409ba679e411e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 27 Mar 2018 19:37:52 +0300 Subject: [PATCH] remove io.write_unsigned_8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and replace with write_unsigned_32, so that is the only used method from the stream Next up, replace the actual “stream” with a binary code writer --- lib/arm/instructions/call_instruction.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 67795a75..1cbdea9a 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -60,20 +60,20 @@ module Arm def write_call(arg,io) raise "else not Attributed arg =\n#{arg.to_s[0..1000]}: #{inspect[0..1000]}" unless (arg.is_a?(Numeric)) - jmp_val = arg >> 2 - packed = [jmp_val].pack('l') - # signed 32-bit, condense to 24-bit - # TODO add check that the value fits into 24 bits - io << packed[0,3] - io.write_unsigned_int_8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4) + val = (arg >> 2) & 0xFFFFFF + raise "too big #{val}" if (val & 0xFFFFFFFF000000) != 0 + val |= shift(op_bit_code , 24) + val |= shift(COND_CODES[@attributes[:condition_code]] , 28) + io.write_unsigned_int_32( val ) end def handle_swi(io) arg = @first raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric)) - packed = [arg].pack('L')[0,3] - io << packed - io.write_unsigned_int_8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) + val = arg & 0xFFFFFF + val |= shift(0b1111 , 24) + val |= shift(COND_CODES[@attributes[:condition_code]] , 28) + io.write_unsigned_int_32 val end def to_s