Sha256: 1c227b7d76f9704356eea32402eb8024a05651e2be1ab2e58f74496426281c10

Contents?: true

Size: 924 Bytes

Versions: 9

Compression:

Stored size: 924 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

9 entries across 9 versions & 1 rubygems

Version Path
HDLRuby-2.1.0 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.18 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.17 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.16 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.15 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.14 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.13 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.9 lib/HDLRuby/hdr_samples/calculator.rb
HDLRuby-2.0.8 lib/HDLRuby/hdr_samples/calculator.rb