bunch of method extraction on instructions

This commit is contained in:
Torsten Ruger
2016-12-14 21:53:26 +02:00
parent 55c108a8d7
commit ec2b0a563e
5 changed files with 63 additions and 59 deletions

View File

@ -12,45 +12,21 @@ module Arm
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
@attributes[:opcode] = attributes[:opcode]
@operand = 0
# @attributes[:update_status]= 0
@rn = :r0 # register zero = zero bit pattern
# downward growing, decrement before memory access
# official ARM style stack as used by gas
@rn = :sp # sp register
end
# don't overwrite instance variables, to make assembly repeatable
def assemble(io)
# don't overwrite instance variables, to make assembly repeatable
operand = @operand
if (@first.is_a?(Array))
operand = 0
@first.each do |r|
raise "nil register in push, index #{r}- #{inspect}" if r.nil?
operand = operand | (1 << reg_code(r))
end
else
raise "invalid operand argument #{inspect}"
operand = 0
raise "invalid operand argument #{inspect}" unless (@first.is_a?(Array))
@first.each do |r|
raise "nil register in push, index #{r}- #{inspect}" if r.nil?
operand = operand | (1 << reg_code(r))
end
write_base = 1
if (opcode == :push)
pre_post_index = 1
up_down = 0
is_pop = 0
else #pop
pre_post_index = 0
up_down = 1
is_pop = 1
end
instuction_class = 0b10 # OPC_STACK
cond = @attributes[:condition_code].is_a?(Symbol) ? COND_CODES[@attributes[:condition_code]] : @attributes[:condition_code]
@rn = :sp # sp register
#assemble of old
val = operand
val = val | (reg_code(@rn) << 16)
val = val | (is_pop << 16 + 4) #20
val = val | (write_base << 16 + 4 + 1)
val = val | (1 << 16 + 4 + 1)
val = val | (@attributes[:update_status] << 16 + 4 + 1 + 1)
val = val | (up_down << 16 + 4 + 1 + 1 + 1)
val = val | (pre_post_index << 16 + 4 + 1 + 1 + 1 + 1)#24
@ -59,9 +35,29 @@ module Arm
io.write_uint32 val
end
def cond
if @attributes[:condition_code].is_a?(Symbol)
COND_CODES[@attributes[:condition_code]]
else
@attributes[:condition_code]
end
end
def instuction_class
0b10 # OPC_STACK
end
def up_down
(opcode == :push) ? 0 : 1
end
alias :is_pop :up_down
def pre_post_index
(opcode == :push) ? 1 : 0
end
def regs
@first
end
def to_s
"#{opcode} [#{@first.join(',') }] #{super}"
end