{"id":25351131,"url":"https://github.com/jmkoni/computer-architecture-with-ruby","last_synced_at":"2025-04-08T22:29:40.587Z","repository":{"id":87882994,"uuid":"70189886","full_name":"jmkoni/computer-architecture-with-ruby","owner":"jmkoni","description":null,"archived":false,"fork":false,"pushed_at":"2017-08-09T19:54:57.000Z","size":399,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T17:43:39.610Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmkoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-06T20:20:39.000Z","updated_at":"2018-12-26T15:44:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"c782ce5d-63bc-4632-a83b-67dbead7e5ad","html_url":"https://github.com/jmkoni/computer-architecture-with-ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmkoni%2Fcomputer-architecture-with-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmkoni%2Fcomputer-architecture-with-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmkoni%2Fcomputer-architecture-with-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmkoni%2Fcomputer-architecture-with-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmkoni","download_url":"https://codeload.github.com/jmkoni/computer-architecture-with-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247939082,"owners_count":21021654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-14T17:38:57.426Z","updated_at":"2025-04-08T22:29:40.580Z","avatar_url":"https://github.com/jmkoni.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Computer Architecture... with Ruby\nWhile learning more about computer architecture, I wrote some Ruby scripts:\n\n* MIPS Disassembler - a program that takes an array of hex or binary and translates it into MIPS instructions\n* Cache Simulation - a program that takes an array or instructions, addresses, and data and updates a simulated cache. Could be altered to take user input.\n* Pipeline Simulation - a program that takes an array of instructions and passes them through each step of a simulated pipeline, updating the registers on each.\n\nView full docs at: https://jmkoni.github.io/computer-architecture-with-ruby\n\nView source code at: https://github.com/jmkoni/computer-architecture-with-ruby\n\n***\n\n### MIPS Disassembler\nThis class disassembles instructions from hex or binary to human readable Mips\n#### Initialization:\n```ruby\nMipsDisassember.new(array_of_instructions, starting_address, is_hex)\n```\n#### Definition of parameters:\n\n* array_of_instructions: an array of instructions in hex or binary. Will generally be strings.\n* starting_address: whatever address you want the instructions to start at\n* is_hex: true or false, depending on whether or not the instructions are hex or not true if hex, false if binary\n\n#### Example:\n```ruby\narray_of_hex = [\"0x022DA822\",\n                \"0x8EF30018\",\n                \"0x12A70004\",\n                \"0x02689820\",\n                \"0xAD930018\",\n                \"0x02697824\",\n                \"0xAD8FFFF4\",\n                \"0x018C6020\",\n                \"0x02A4A825\",\n                \"0x158FFFF6\",\n                \"0x8E59FFF0\"]\n\nmips = MipsDisassembler.new(array_of_hex, \"7A060\", true)\nresults = mips.disassemble\nresults.each { |instruction| puts instruction }\n```\n\n#### Output:\n```\n    7A060 sub $21 $17 $13\n    7a064 lw $19, 24 ($23)\n    7a068 beq $7, $21, address 0x7a07c\n    7a06c add $19 $19 $8\n    7a070 sw $19, 24 ($12)\n    7a074 and $15 $19 $9\n    7a078 sw $15, -12 ($12)\n    7a07c add $12 $12 $12\n    7a080 or $21 $21 $4\n    7a084 bne $15, $12, address 0xba060\n    7a088 lw $25, -16 ($18)\n```\n\n***\n\n### Cache Simulation\nThis class creates a simulation of a cache. Currently it is built to\ntake in an array of actions. It could easily be rewritten to take in user\ninput instead.\n\n#### Initialization:\n```ruby\ncache = CacheSim::Cache.new(size)\n```\n\n#### Definition of parameters:\n\n* size: integer, reflects the number and size of slots. Ex. with this one, there are 16 slots and each slot has space for 16 pieces of data\n* operations: a list of operations Ex: [\"R\", \"4C3\", \"D\", \"W\", \"14C\", \"99\"]\n\n#### Example:\n```ruby\ncache = CacheSim::Cache.new(16)\ncache.perform_actions([\"R\", \"4C3\", \"D\", \"W\", \"14C\", \"99\"])\n```\n\n#### Output:\n```\n    (R)ead, (W)rite, or (D)isplay cache?\n    R\n    What address would you like read?\n    4C3\n    At that byte, there is the value c3 (Cache miss)\n    (R)ead, (W)rite, or (D)isplay cache?\n    D\n    Slot | Valid | Tag | Data\n      0  |   1   |  0  | 0 1 2 3 4 5 6 7 8 9 a b c d e f\n      1  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      2  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      3  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      4  |   1   |  1  | 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f\n      5  |   1   |  1  | 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f\n      6  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      7  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      8  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      9  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      a  |   1   |  3  | a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af\n      b  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      c  |   1   |  4  | c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf\n      d  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      e  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n      f  |   0   |  0  | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n    (R)ead, (W)rite, or (D)isplay cache?\n    W\n    What address would you like to write to?\n    14C\n    What data would you like to write at that address?\n    99\n```\n\n***\n\n### Pipeline Simulation\nThis class creates a simulation of a pipeline.\n\n#### Initialization:\n```ruby\nsimulation = PipelineSim.new(starting_address)\nsimulation.runthrough(instructions)\n```\n\n#### Definition of parameters:\n* starting_address: starting address of the first instruction (in hex)\n* instructions: array of mips instructions, in hex\n\n#### Example:\n```ruby\ninstructions = [\"0x00a63820\",\n                \"0x8d0f0004\",\n                \"0xad09fffc\",\n                \"0x00625022\",\n                \"0x00000000\",\n                \"0x00000000\",\n                \"0x00000000\",\n                \"0x00000000\"]\nsimulation = PipelineSim.new(\"0x70000\")\nsimulation.runthrough(instructions)\n```\n\n#### Output:\n```\n    -----------------\n    | Clock Cycle 1 |\n    -----------------\n    Regs: 0, 101, 102, 103, 104, 105, 106, 107, 108, 109, 10a, 10b, 10c, 10d, 10e, 10f, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 11a, 11b, 11c, 11d, 11e, 11f, 120\n\n\n    IF/ID Register Write\n    --------------------\n    instruction = 0xa1020000  incrPC = 70004\n\n    IF/ID Register Read\n    --------------------\n    instruction = 0x00000000\n\n\n    ID/EX Register Write\n    --------------------\n    control = 000000000\n\n    ID/EX Register Read\n    --------------------\n    control = 000000000\n\n\n    EX/MEM Register Write\n    --------------------\n    control = 000000000\n\n    EX/MEM Register Read\n    --------------------\n    control = 000000000\n\n\n    MEM/WB Register Write\n    --------------------\n    control = 000000000\n\n    MEM/WB Register Read\n    --------------------\n    control = 000000000\n\n\n    -----------------\n    | Clock Cycle 2 |\n    -----------------\n    Regs: 0, 101, 102, 103, 104, 105, 106, 107, 108, 109, 10a, 10b, 10c, 10d, 10e, 10f, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 11a, 11b, 11c, 11d, 11e, 11f, 120\n\n\n    IF/ID Register Write\n    --------------------\n    instruction = 0x810AFFFC  incrPC = 70008\n\n    IF/ID Register Read\n    --------------------\n    instruction = 0xa1020000  incrPC = 70004\n\n\n    ID/EX Register Write\n    --------------------\n    Control: regWrite = 0, regDest = X, memToReg = X, memRead = 0, memWrite = 1, aLUSrc = 1, branch = 0, aLUOp = 0,\n    sEOffset = 0  function = X  writeReg_15_11 = 0  writeReg_20_16 = 2  readReg1Value = 108  readReg2Value = 102  incrPC = 70004\n\n    ID/EX Register Read\n    --------------------\n    control = 000000000\n\n\n    EX/MEM Register Write\n    --------------------\n    control = 000000000\n\n    EX/MEM Register Read\n    --------------------\n    control = 000000000\n\n\n    MEM/WB Register Write\n    --------------------\n    control = 000000000\n\n    MEM/WB Register Read\n    --------------------\n    control = 000000000\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmkoni%2Fcomputer-architecture-with-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmkoni%2Fcomputer-architecture-with-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmkoni%2Fcomputer-architecture-with-ruby/lists"}