2018-03-27 19:47:41 +02:00
|
|
|
module Risc
|
|
|
|
# Little glue class to get the assembled binary from the Arm Instructions into
|
|
|
|
# the BinaryCode instances. Arm code originally uses io, but slightly modified
|
|
|
|
# really only uses write_unsigned_int_32 , which converts
|
|
|
|
# to an set_internal_word on the BinaryCode
|
|
|
|
#
|
|
|
|
# Machine instantiates and the writer reads from the arm Instructions
|
|
|
|
# and writes to the BinaryCode
|
|
|
|
class BinaryWriter
|
|
|
|
def initialize( code )
|
|
|
|
@code = code
|
|
|
|
end
|
|
|
|
|
2018-03-28 18:49:16 +02:00
|
|
|
# Go through and assemble all instructions.
|
2018-05-01 18:48:11 +02:00
|
|
|
def assemble( instruction )
|
2018-05-14 14:17:04 +02:00
|
|
|
@index = 0
|
2018-03-28 18:49:16 +02:00
|
|
|
while(instruction)
|
|
|
|
instruction.assemble(self)
|
2018-03-27 19:47:41 +02:00
|
|
|
instruction = instruction.next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_unsigned_int_32( bin )
|
|
|
|
@code.set_word( @index , bin )
|
|
|
|
@index += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-25 18:03:46 +02:00
|
|
|
#even less glue to get that last jump in there.
|
|
|
|
# So instructions don't run into the BinaryCode object header
|
|
|
|
class JumpWriter
|
|
|
|
def initialize( code )
|
|
|
|
@code = code
|
|
|
|
end
|
|
|
|
def write_unsigned_int_32( bin )
|
|
|
|
@code.set_word( 14 , bin )
|
|
|
|
end
|
|
|
|
end
|
2018-03-27 19:47:41 +02:00
|
|
|
end
|