Created
February 1, 2009 23:43
-
-
Save dodeja/56700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ECE 486 Project 1 | |
# PDP 8 Benchmarking tool | |
# | |
f = File.open("add01.obj","r") | |
lines = f.readlines | |
f.close | |
prog_data = Hash.new { |hash, key| hash[key] = {:addr => "", :data => ""} } | |
ins = 0 | |
first_addr = false | |
lines.each_index do |x| | |
if(x % 2 == 0) | |
if(lines[x].index('1') == 0) | |
prog_data[ins][:addr] = lines[x][1..2].to_i.to_s + lines[x + 1][1..2] | |
prog_data[ins][:data] = lines[x + 2][1..2] + lines[x + 3][1..2] | |
ins = ins + 1 | |
first_addr = true | |
else | |
if(!first_addr) | |
prog_data[ins][:addr] = (prog_data[ins-1][:addr].to_i + 1).to_s | |
prog_data[ins][:data] = lines[x][1..2] + lines[x + 1][1..2] | |
ins = ins + 1 | |
else | |
first_addr = false | |
end | |
end | |
end | |
end | |
0.upto(prog_data.length-1) do |l| | |
puts "#{prog_data[l][:addr]} #{prog_data[l][:data]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment