Skip to content

Example code

Felipe Martínez edited this page Oct 30, 2021 · 10 revisions

Here are a few snippets of LogicScript code to give you a feel for the language:

// This script doesn't do anything useful

input a
input b
input'3 data

output z
output'2 out

const myconst = 123

reg'3 mem

assign out = 3
assign z = (myconst)'1

startup
    @print "Hello world"
end

when *
    if 1 == 2
        @print "Not equal"
    else
        @print "Equal"
    end

    local $test = 1010b
    @print "Test: $test hex: $test:x binary: $test:b"

    $test '= $test + 1
    @print $test

    for $i to 5
        $test = $test - $i
    end

    local $mul = $test * 2

    out = ($mul)'2
end

Simple counter:

input add1
output'4 result

reg'4 val

when add1
    val '= val + 1
    result = val
end

Multiplexer:

input sel
input'2 data
output out

assign out = sel ? data[0] : data[1]
Clone this wiki locally