389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
# File 'lib/micro_cisc/vm/processor.rb', line 389
def ucisc(word)
source = (word & SOURCE_MASK) >> SOURCE_SHIFT
destination = (word & DESTINATION_MASK) >> DESTINATION_SHIFT
effect = (word & EFFECT_MASK) >> EFFECT_SHIFT
src =
if source == 0
'0.reg'
elsif source < 4
"#{source}.mem"
elsif source == 4
'4.val'
else
"#{source - 4}.reg"
end
dest =
if destination == 0
'0.reg'
elsif destination < 4
"#{destination}.mem"
elsif destination == 4
'4.reg'
else
"#{destination - 4}.reg"
end
signed = !MEM_ARGS.include?(source)
inc_is_immediate = signed && !MEM_ARGS.include?(destination)
is_copy = (word & OP_MASK) == 0
half_width = is_copy && MEM_ARGS.include?(source) && MEM_ARGS.include?(destination)
immediates = (word, is_copy, inc_is_immediate, signed, half_width)
value = source_value(source, immediates.first)
store = store?(@flags, effect)
alu = word & ALU_OP_MASK
result = compute_result(is_copy, source, destination, immediates, alu, true)
alu = is_copy ? '' : "0x#{alu.to_s(16).upcase}.op "
imm0 = immediates.first < 0 ? "-#{(immediates.first * -1)}.imm" : "#{immediates.first}.imm"
imm1 =
if half_width
immediates.last < 0 ? "-#{(immediates.last * -1)}.imm " : "#{immediates.last}.imm "
else
""
end
eff = "#{effect}.eff"
push = !inc_is_immediate && (word & INCREMENT_MASK) > 0
push = push ? 'push ' : ''
ins = is_copy ? 'copy' : 'compute'
"Stack: #{stack_string}\n#{ins} #{alu}#{src} #{imm0} #{dest} #{imm1}#{eff} #{push}# value: #{value} (0x#{'%04x' % value}), result: #{result} (0x#{'%04x' % result}), #{'not ' if !store}stored"
end
|