Sha256: 65104f8a4b764967af29c03a8b6e5a1b6a3638066b174f369e306eaaccda21f7

Contents?: true

Size: 1.24 KB

Versions: 100

Compression:

Stored size: 1.24 KB

Contents

# A simple ALU
system :alu do
    [4].input  :opr
    [16].input :x,:y
    [16].output :s
    output :zf, :cf, :sf, :vf

    # The only adder instance.
    instance :add do
        [16].input :x,:y
        input :cin
        [17].output :s
        
        s <= x+y+cin
    end

    # The control part for choosing between 0, add, sub and neg.
    par do
        # The main computation: s and cf
        # Default connections
        cf <= 0
        vf <= 0
        add.(0,0,0)
        # Depending on the operator
        hcase(opr)
        hwhen(1) { s <= x }
        hwhen(2) { s <= y }
        hwhen(3) { add.(x ,y ,0,[cf,s])
                   vf <= (~x[15] & ~y[15] & s[15]) | (x[15] & y[15] & ~s[15]) }
        hwhen(4) { add.(x ,~y,1,[cf,s])
                   vf <= (~x[15] & y[15] & s[15]) | (x[15] & ~y[15] & ~s[15]) }
        hwhen(5) { add.(0 ,~y,1,[cf,s])
                   vf <= (~y[15] & s[15]) }
        hwhen(6) { add.(~x,0 ,1,[cf,s])
                   vf <= (x[15] & ~s[15]) }
        hwhen(7) { s <= x & y }
        hwhen(8) { s <= x | y }
        hwhen(9) { s <= x ^ y }
        hwhen(10){ s <= ~x }
        hwhen(11){ s <= ~y }
        helse    { s <= 0 }

        # The remaining flags.
        zf <= (s == 0)
        sf <= s[15]
    end
end

Version data entries

100 entries across 100 versions & 1 rubygems

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