Created
February 3, 2009 01:40
-
-
Save dodeja/57232 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # | |
| class PDP8 | |
| 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 | |
| ac = 0 # => Accumulator | |
| program_counter = 200 # => Program Counter starts at 200 | |
| prog_addr = Hash.new | |
| 0.upto(prog_data.length-1) do |k| | |
| prog_addr[prog_data[k][:addr].to_i] = prog_data[k][:data] | |
| end | |
| lines.each_index do |x| | |
| if(x % 2 == 0) | |
| if(lines[x].index('1') == 0) | |
| prog_data[ins][:addr] = "0" + 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] = "0" + (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]}" | |
| current_data = prog_data[l][:data] | |
| current_instruction = current_data[0..0].to_i | |
| pc = prog_data[l][:addr] | |
| eaddr = "" | |
| temp_data = 0 | |
| case current_instruction | |
| when 0 | |
| if(current_data[1..1].to_i < 4) | |
| if(current_data[1..1].to_i < 2) | |
| eaddr = (current_data[1..1].to_i % 2).to_s + current_data[2..3] | |
| else | |
| eaddr = (pc[0..1].to_i*100 + (current_data[1..1].to_i % 2)*100 + current_data[2..3].to_i).to_s | |
| end | |
| elsif( current_data[1..1].to_i > 4 && current_data[1..1].to_i < 6) | |
| eaddr = (current_data[1..1].to_i % 2).to_s + current_data[2..3] | |
| eaddr =prog_addr[eaddr.to_i] | |
| else | |
| eaddr = (pc[0..1].to_i*100 + (current_data[1..1].to_i % 2)*100 + current_data[2..3].to_i).to_s | |
| eaddr = prog_addr[eaddr.to_i] | |
| end | |
| temp_data = prog_addr[eaddr.to_i] | |
| ac = temp_data.to_s.oct & ac.to_s.oct | |
| ac = ac.to_s(8).to_i | |
| end | |
| end | |
| def stats | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment