rips 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf8c8bebaebfc51d045b029332f2cd2e061a88bf
4
- data.tar.gz: 308c2b211e7feb112d7bbe80e3532771004efbf1
3
+ metadata.gz: 2e4896a53632a2c27fb558be1aff1d7d8091771b
4
+ data.tar.gz: 7024219596467dca132f8fb4c2dfe283e32d4a7e
5
5
  SHA512:
6
- metadata.gz: efa9aa5de99297bee011ab544cf5d19d7759750141f022fa14c73a3d89b799fe77cba869fc1fa1e8302a0d924bb2ba8bbad267226043aca648940e28e622b6e5
7
- data.tar.gz: ebb7b52fae71dfa37e44ae6ba8bccca459343567fbda81d5354c5eec09a653a07019afdb8946611f7faa4af933b70b53a1bc9a5c9e48abc513753123784dd349
6
+ metadata.gz: 82e18c0c6144ee40e2d1cbbfbad0fd6d53c28c46e1714faf8ba896c0a4e1bade33d5c451a614ee9ff65abaca04e8677e70dfcd8c4d27df2bc155747ac5571db6
7
+ data.tar.gz: 6d05c42a402851adbffbfb36c94914cf1148399064bf5379f1160f1fc3e767c2944372eee1580d69c63a38c7e0abf554e9d0aa53b425e61565f903ab31f7a8e2
@@ -1,3 +1,18 @@
1
1
  require "rips/instructions/add"
2
+ require "rips/instructions/and"
3
+ require "rips/instructions/bez"
4
+ require "rips/instructions/bnez"
5
+ require "rips/instructions/j"
6
+ require "rips/instructions/jal"
7
+ require "rips/instructions/ji"
8
+ require "rips/instructions/jr"
9
+ require "rips/instructions/lesr"
2
10
  require "rips/instructions/li"
11
+ require "rips/instructions/move"
12
+ require "rips/instructions/nop"
13
+ require "rips/instructions/neg"
14
+ require "rips/instructions/not"
15
+ require "rips/instructions/or"
16
+ require "rips/instructions/sesm"
17
+ require "rips/instructions/sesr"
3
18
  require "rips/instructions/sub"
@@ -12,7 +12,7 @@ module Rips
12
12
  def initialize
13
13
  super("add",Formats::DFormat.new(0b0010))
14
14
  @variables = [Variables::Register.new, Variables::Register.new, Variables::Register.new]
15
- @length = {r3:4, r2:4, r1:4}
15
+ @length = {r3:4, r2:4, r1:4, op:4}
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class And < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("and",Formats::DFormat.new(0b0100))
14
+ @variables = [Variables::Register.new, Variables::Register.new, Variables::Register.new]
15
+ @length = {r3:4, r2:4, r1:4, op:4}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Bez < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("bez",Formats::BFormat.new(0b001111))
14
+ @variables = [Variables::Address.new]
15
+ @length = {r1:10, op:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Bnez < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("bnez",Formats::BFormat.new(0b011111))
14
+ @variables = [Variables::Address.new]
15
+ @length = {r1:10, op:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -9,9 +9,11 @@ module Rips
9
9
 
10
10
  # @name: mnemonic name
11
11
  # @format: instruction format
12
+ # @output: array with coded instruction
12
13
  def initialize (name, format)
13
14
  @name,@format = name,format
14
15
  @opcode = format.opcode
16
+ @output = []
15
17
  end
16
18
 
17
19
  # Return number of arguments
@@ -24,18 +26,34 @@ module Rips
24
26
  @format.set_arguments(args)
25
27
  end
26
28
 
29
+ # Add blanks (0 values) for instructions with free space
30
+ def add_blank
31
+ if @variables.empty?
32
+ @output.push(0.to_bin(@length[:blank]))
33
+ elsif @variables.size == 1
34
+ @output.insert(-2,0.to_bin(@length[:blank]))
35
+ else
36
+ @output.insert(-@variables.size,0.to_bin(@length[:blank]))
37
+ end
38
+ end
39
+
27
40
  # Coding to Machine Code
28
41
  def code
29
42
 
30
- output = [@opcode.to_bin(@opcode.size)]
43
+ # Add opcode
44
+ @output = [@opcode.to_bin(@length[:op])]
31
45
 
46
+ # Add arguments
32
47
  @format.args.each do |key,value|
33
- output << value.to_bin(@length[key])
48
+ @output << value.to_bin(@length[key])
34
49
  end
35
50
 
36
- output.insert(-2,@length[:blank]) if (@length.key? :blank)
51
+ # Add blanks
52
+ if (@length.key? :blank)
53
+ add_blank
54
+ end
37
55
 
38
- output.reverse.join.to_s
56
+ @output.reverse.join.to_s
39
57
  end
40
58
 
41
59
  end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class J < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("j",Formats::BFormat.new(0b1001))
14
+ @variables = [Variables::Address.new]
15
+ @length = {r1:10, op:4, blank:2}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Jal < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("jal",Formats::BFormat.new(0b101000))
14
+ @variables = [Variables::Address.new]
15
+ @length = {r1:10, op:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Ji < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("ji",Formats::BFormat.new(0b011000))
14
+ @variables = [Variables::Inmediate.new(10)]
15
+ @length = {r1:10, op:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Jr < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("jr",Formats::AFormat.new(0b111000))
14
+ @variables = []
15
+ @length = {op:6, blank:10}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Lesr < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("lesr",Formats::CFormat.new(0b1011))
14
+ @variables = [Variables::Register.new, Variables::Port.new]
15
+ @length = {r2:4, r1:2, op:4, blank:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -12,7 +12,7 @@ module Rips
12
12
  def initialize
13
13
  super("li",Formats::CFormat.new(0b1010))
14
14
  @variables = [Variables::Register.new, Variables::Inmediate.new]
15
- @length = {r2:4, r1:8}
15
+ @length = {r2:4, r1:8, op:4}
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Move < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("move",Formats::CFormat.new(0b0000))
14
+ @variables = [Variables::Register.new, Variables::Register.new]
15
+ @length = {r2:4, r1:4, op:4, blank:4}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Neg < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("neg",Formats::CFormat.new(0b0110))
14
+ @variables = [Variables::Register.new, Variables::Register.new]
15
+ @length = {r2:4, r1:4, op:4, blank:4}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Nop < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("nop",Formats::AFormat.new(0b111111))
14
+ @variables = []
15
+ @length = {op:6, blank:10}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Not < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("not",Formats::CFormat.new(0b0001))
14
+ @variables = [Variables::Register.new, Variables::Register.new]
15
+ @length = {r2:4, r1:4, op:4, blank:4}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Or < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("or",Formats::DFormat.new(0b0101))
14
+ @variables = [Variables::Register.new, Variables::Register.new, Variables::Register.new]
15
+ @length = {r3:4, r2:4, r1:4, op:4}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Sesm < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("sesm",Formats::CFormat.new(0b1110))
14
+ @variables = [Variables::Port.new, Variables::Inmediate.new]
15
+ @length = {r2:2, r1:8, op:4, blank:2}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rips/instructions/instruction"
2
+
3
+ module Rips
4
+ module Instructions
5
+
6
+ class Sesr < Instruction
7
+
8
+ attr_reader :variables, :length
9
+
10
+ # @variables: types of instruction's variables
11
+ # @length: length in bits for each variable
12
+ def initialize
13
+ super("sesr",Formats::CFormat.new(0b1101))
14
+ @variables = [Variables::Port.new, Variables::Register.new]
15
+ @length = {r2:2, r1:4, op:4, blank:6}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,24 @@
1
1
  module Rips
2
2
  module Instructions
3
3
 
4
- SET = ["add", "li", "sub"]
4
+ SET =
5
+ [ "add",
6
+ "and",
7
+ "j",
8
+ "jal",
9
+ "ji",
10
+ "jr",
11
+ "bez",
12
+ "bnez",
13
+ "lesr",
14
+ "li",
15
+ "move",
16
+ "nop",
17
+ "neg",
18
+ "not",
19
+ "or",
20
+ "sesm",
21
+ "sesr",
22
+ "sub" ]
5
23
  end
6
24
  end
@@ -12,8 +12,14 @@ module Rips
12
12
  def initialize
13
13
  super("sub",Formats::DFormat.new(0b0011))
14
14
  @variables = [Variables::Register.new, Variables::Register.new, Variables::Register.new]
15
- @length = {r3:4, r2:4, r1:4}
15
+ @length = {r3:4, r2:4, r1:4, op:4}
16
16
  end
17
+
18
+ # Swap subtractor
19
+ def set_arguments (args)
20
+ args[1], args[2] = args[2], args[1]
21
+ super
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -9,10 +9,10 @@ module Rips
9
9
 
10
10
  # @syntax: example syntax
11
11
  # @range: bit's range for variable
12
- def initialize
13
- super(10)
14
- @syntax = "0..1023"
12
+ def initialize(size = 10)
13
+ super(size)
15
14
  @range = [0, 2**@length-1]
15
+ @syntax = "#{@range[0]}..{@range[1]}"
16
16
  end
17
17
 
18
18
  # Check input variable syntax
@@ -9,10 +9,10 @@ module Rips
9
9
 
10
10
  # @syntax: example syntax
11
11
  # @range: bit's range for variable
12
- def initialize
13
- super(8)
14
- @syntax = "-128..127"
12
+ def initialize(size = 8)
13
+ super(size)
15
14
  @range = [-2**(@length-1), 2**(@length-1)-1]
15
+ @syntax = "#{@range[0]}..{@range[1]}"
16
16
  end
17
17
 
18
18
  # Check input variable syntax
@@ -9,10 +9,11 @@ module Rips
9
9
 
10
10
  # @syntax: example syntax
11
11
  # @range: bit's range for variable
12
- def initialize
13
- super(2)
12
+ def initialize(size = 2)
13
+ super(size)
14
14
  @syntax = "@0-3"
15
15
  @range = [0, 2**@length-1]
16
+ @syntax = "@#{@range[0]}-{@range[1]}"
16
17
  end
17
18
 
18
19
  # Check input variable syntax
@@ -9,10 +9,10 @@ module Rips
9
9
 
10
10
  # @syntax: example syntax
11
11
  # @range: bit's range for variable
12
- def initialize
13
- super(4)
14
- @syntax = "$0-15"
12
+ def initialize(size = 4)
13
+ super(size)
15
14
  @range = [0, 2**@length-1]
15
+ @syntax = "$#{@range[0]}-{@range[1]}"
16
16
  end
17
17
 
18
18
  # Check input variable syntax
@@ -1,3 +1,3 @@
1
1
  module Rips
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rips
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Madh93
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,8 +79,23 @@ files:
79
79
  - lib/rips/formats/format.rb
80
80
  - lib/rips/instructions.rb
81
81
  - lib/rips/instructions/add.rb
82
+ - lib/rips/instructions/and.rb
83
+ - lib/rips/instructions/bez.rb
84
+ - lib/rips/instructions/bnez.rb
82
85
  - lib/rips/instructions/instruction.rb
86
+ - lib/rips/instructions/j.rb
87
+ - lib/rips/instructions/jal.rb
88
+ - lib/rips/instructions/ji.rb
89
+ - lib/rips/instructions/jr.rb
90
+ - lib/rips/instructions/lesr.rb
83
91
  - lib/rips/instructions/li.rb
92
+ - lib/rips/instructions/move.rb
93
+ - lib/rips/instructions/neg.rb
94
+ - lib/rips/instructions/nop.rb
95
+ - lib/rips/instructions/not.rb
96
+ - lib/rips/instructions/or.rb
97
+ - lib/rips/instructions/sesm.rb
98
+ - lib/rips/instructions/sesr.rb
84
99
  - lib/rips/instructions/set.rb
85
100
  - lib/rips/instructions/sub.rb
86
101
  - lib/rips/utils.rb