Sha256: 676746e0f81451514b91bb708c02e450365a3e884c0c78c0d57e679e0f15fcc9

Contents?: true

Size: 921 Bytes

Versions: 91

Compression:

Stored size: 921 Bytes

Contents

require 'std/fsm.rb'

include HDLRuby::High::Std

# Implementation of an 8-bit calculator.
system :calculator do
    input :clk,:rst
    [1..0].input :opr
    [7..0].input :x, :y
    [7..0].output :s
    output :zf, :sf, :cf, :vf

    [8..0].inner :tmp

    def common
        s   <= tmp[7..0]
        zf  <= (s == 0)
        sf  <= tmp[7]
        cf  <= tmp[8]
        vf  <= tmp[8] ^ tmp[7]
        goto(:choice)
    end

    fsm(clk.posedge,rst) do
        state(:zero) do
            s <= 0;
            zf <= 0;
            sf <= 0;
            cf <= 0;
            vf <= 0;
        end
        state(:choice) do
            goto(opr, :add,:sub,:neg, :zero)
        end
        state(:add) do
            tmp <= x + y
            common
        end
        state(:sub) do
            tmp <= x - y
            common
        end
        state(:neg) do
            tmp <= -x
            common
        end
    end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
HDLRuby-3.4.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.3.4 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.3.3 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.3.1 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.3.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.2.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.1.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-3.0.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.12 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.11 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.10 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.9 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.8 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.7 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.5 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.4 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.3 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.2 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.11.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.10.5 lib/HDLRuby/hdr_samples/calculator.rb