ASMOperations 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +18 -0
- data/bin/asmp +48 -0
- data/lib/asm_operations.rb +10 -0
- data/lib/asm_operations/version.rb +3 -0
- data/lib/types/binary.rb +63 -0
- data/lib/types/decimal.rb +23 -0
- data/lib/types/hex.rb +25 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89740ea8468f7681e4df347d129c9dab9c6ed590
|
4
|
+
data.tar.gz: 309be8c07a634cd9d406bf7b558f9ce2f45d0865
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc0be576c1f12c5d84eeae183345397f8581be793b442cbae6a0814e5ede53f343b9897691b2814da8cfcfac4838dff9e4f56705cc9e9a197f5fc40cbd033b6d
|
7
|
+
data.tar.gz: 8dac4feba9bb9d4757f9db6699a471baf3f7950f126f8ce7bfaac782ab3a91a8e16353ff3de0f7eb87b0a008c5f14b9bc7ad795e946a91758555cf5e11e40110
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
###ASMOperations
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/leftis/ASMOperations.svg?branch=master)](https://travis-ci.org/leftis/ASMOperations)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/leftis/ASMOperations.svg)](https://coveralls.io/r/leftis/ASMOperations)
|
5
|
+
|
6
|
+
I am reading Assembly Language for x86 Processors, 7/e - Kip Irvine this repository is the implementation in high level language wanted by the book.
|
7
|
+
|
8
|
+
####Simple CLI added
|
9
|
+
ASMOperations ships with a basic thor cli. Run in your console
|
10
|
+
**asmp** and converting options will show up.
|
11
|
+
|
12
|
+
####Intentions
|
13
|
+
- Add basic add, substractions operations between all types
|
14
|
+
- Add logic gates operations between all types
|
15
|
+
- Suggest more...
|
16
|
+
|
17
|
+
#####This project is for fun and about learning assembly as i describe on top of README.
|
18
|
+
|
data/bin/asmp
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'thor'
|
7
|
+
require 'asm_operations'
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
module ASMOperations
|
11
|
+
class CLI < Thor
|
12
|
+
desc 'b2d', 'Converts binary to decimal'
|
13
|
+
def b2d(binary)
|
14
|
+
puts Binary.new(binary).to_decimal
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'b2h', 'Converts binary to hex'
|
18
|
+
def b2h(binary)
|
19
|
+
puts Binary.new(binary).to_hex
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'd2b', 'Converts decimal to binary'
|
23
|
+
def d2b(decimal)
|
24
|
+
decimal = Decimal.new(decimal)
|
25
|
+
puts decimal.binary
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'd2h', 'Converts decimal to hex'
|
29
|
+
def d2h(decimal)
|
30
|
+
decimal = Decimal.new(decimal)
|
31
|
+
puts decimal.to_hex
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'h2b', 'Converts hexademical to binary'
|
35
|
+
def h2b(hex)
|
36
|
+
hex = Hex.new(hex)
|
37
|
+
puts hex.binary
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'h2d', 'Converts hexademical to decimal'
|
41
|
+
def h2d(hex)
|
42
|
+
hex = Hex.new(hex)
|
43
|
+
puts b2d(hex.binary)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ASMOperations::CLI.start(ARGV)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ASMOperations
|
2
|
+
HEX_TABLE = {
|
3
|
+
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7,
|
4
|
+
'8' => 8, '9' => 9, 'A' =>10, 'B' =>11, 'C' =>12, 'D' =>13, 'E' =>14, 'F' => 15
|
5
|
+
}
|
6
|
+
|
7
|
+
autoload :Decimal, 'types/decimal'
|
8
|
+
autoload :Binary, 'types/binary'
|
9
|
+
autoload :Hex, 'types/hex'
|
10
|
+
end
|
data/lib/types/binary.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module ASMOperations
|
2
|
+
class Binary
|
3
|
+
attr_accessor :bit_count, :binary, :errors, :warnings
|
4
|
+
|
5
|
+
def initialize(unsigned_binary)
|
6
|
+
@errors, @warnings = [], []
|
7
|
+
@binary = unsigned_binary
|
8
|
+
@bit_count = count_bits and unsigned?
|
9
|
+
fix_bytes
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_decimal
|
13
|
+
bits_powers.reduce(0) do |acc, pow|
|
14
|
+
acc += 2**pow
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hex
|
19
|
+
binary.split('').each_slice(4).to_a.map do |binary_slice|
|
20
|
+
decimal = Binary.new(binary_slice.join('')).to_decimal
|
21
|
+
ASMOperations::HEX_TABLE.invert[decimal]
|
22
|
+
end.join('')
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fix_bytes
|
28
|
+
return false if @binary.length == bit_count || bit_count == 0
|
29
|
+
remaining_bits = bit_count - @binary.length
|
30
|
+
@binary = Array.new(remaining_bits) { '0' }.join('') + @binary
|
31
|
+
end
|
32
|
+
|
33
|
+
def bits_powers
|
34
|
+
@binary.split('').reverse.map.with_index(0).to_a.map do |object|
|
35
|
+
next if object.first == '0'
|
36
|
+
object.last
|
37
|
+
end.compact
|
38
|
+
end
|
39
|
+
|
40
|
+
def unsigned?
|
41
|
+
return if @binary.split('').first == '0'
|
42
|
+
@warnings << 'Number is a signed one'
|
43
|
+
end
|
44
|
+
|
45
|
+
def count_bits
|
46
|
+
case @binary.split('').length
|
47
|
+
when 1..4
|
48
|
+
4
|
49
|
+
when 5..8
|
50
|
+
8
|
51
|
+
when 9..16
|
52
|
+
16
|
53
|
+
when 17..32
|
54
|
+
32
|
55
|
+
when 33..64
|
56
|
+
64
|
57
|
+
else
|
58
|
+
@errors.push 'Not an 8 || 16 || 32 || 64 bit'
|
59
|
+
0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ASMOperations
|
2
|
+
class Decimal < Binary
|
3
|
+
attr_accessor :decimal
|
4
|
+
|
5
|
+
def initialize(decimal)
|
6
|
+
@decimal = decimal
|
7
|
+
super(self.to_binary)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_binary
|
11
|
+
remaining, _bit = decimal.to_i, 0
|
12
|
+
bits = (remaining == 0 ? [0, 0, 0, 0] : [])
|
13
|
+
|
14
|
+
while remaining > 0
|
15
|
+
bits.push(remaining % 2)
|
16
|
+
remaining /= 2
|
17
|
+
end
|
18
|
+
|
19
|
+
bits.reverse!
|
20
|
+
bits.map!(&:to_s).join('')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/types/hex.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module ASMOperations
|
2
|
+
class Hex < Binary
|
3
|
+
attr_accessor :hex
|
4
|
+
|
5
|
+
def initialize(hex)
|
6
|
+
@hex = hex
|
7
|
+
super(to_binary)
|
8
|
+
end
|
9
|
+
|
10
|
+
def fix_byte(byte)
|
11
|
+
return byte if byte.length == 4 || byte.empty?
|
12
|
+
remaining_bits = 4 - byte.length
|
13
|
+
Array.new(remaining_bits) { '0' }.join('') + byte
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_binary
|
17
|
+
binary = []
|
18
|
+
hex.split('').map do |element|
|
19
|
+
hexed_element = HEX_TABLE.keys.detect { |k| k.match(Regexp.new(element, Regexp::IGNORECASE)) }
|
20
|
+
binary << fix_byte(ASMOperations::Decimal.new(HEX_TABLE[hexed_element.to_s]).binary)
|
21
|
+
end
|
22
|
+
binary.join('')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ASMOperations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lefteris Georgatos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.1
|
55
|
+
description: Simple project, right now supports only basic types, later on i will
|
56
|
+
add more assembly operations
|
57
|
+
email: lefteros.georgatos@gmail.com
|
58
|
+
executables:
|
59
|
+
- asmp
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- bin/asmp
|
65
|
+
- lib/asm_operations.rb
|
66
|
+
- lib/asm_operations/version.rb
|
67
|
+
- lib/types/binary.rb
|
68
|
+
- lib/types/decimal.rb
|
69
|
+
- lib/types/hex.rb
|
70
|
+
homepage: http://georgatos.gr
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Assembly types and operations
|
94
|
+
test_files: []
|