236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/micro_cisc/compile/instruction.rb', line 236
def validate_immediate(value, index)
width = @bit_width
width = width / 2 if @operation == 'copy' && @source_is_mem && @dest_is_mem
if index == 0 && @source_is_mem || index == 1 && @dest_is_mem
min = 0
max = (1 << width) - 1
else
magnitude = 1 << (width - 1)
min = magnitude * -1
max = magnitude - 1
end
if (value < min || value > max)
signed = @source_is_mem ? 'unsigned' : 'signed'
raise ArgumentError, "Immediate max bits is #{width} #{signed}; value must be between #{min} and #{max} instead of #{value}"
end
end
|