2024-06-16 18:18:28 -05:00
|
|
|
payload = """
|
2024-02-01 17:00:28 -06:00
|
|
|
ticker 1 : main
|
2023-11-14 22:33:34 -06:00
|
|
|
# Main memory structure
|
2024-06-16 18:18:28 -05:00
|
|
|
# This should be filled in with an override
|
|
|
|
id testing : B = []
|
2023-11-14 22:33:34 -06:00
|
|
|
# Operations on memory
|
2023-11-15 20:01:35 -06:00
|
|
|
: q(l, v, i)=ifval(l, i, [1...length(l)], v)
|
|
|
|
: setlistval(index, v) = B -> q(B, v, index)
|
|
|
|
: incx(index, v) = setlistval(index, B[index] + v)
|
|
|
|
: ifval(l, index, c, v) = {c = index : v, l[c]}
|
|
|
|
|
|
|
|
# Operations
|
|
|
|
: oadd(x, y) = x + y
|
|
|
|
: osub(x, y) = x - y
|
|
|
|
: odiv(x, y) = x / y
|
|
|
|
: omul(x, y) = x * y
|
|
|
|
|
|
|
|
# Instruction implementation
|
|
|
|
: ijmp(a, b, c) = ip -> a, jumped -> 1
|
|
|
|
: iadd(a, b, t_o) = setlistval(t_o, oadd(B[a], B[b]))
|
|
|
|
: isub(a, b, t_o) = setlistval(t_o, osub(B[a], B[b]))
|
|
|
|
: idiv(a, b, t_o) = setlistval(t_o, odiv(B[a], B[b]))
|
|
|
|
: imul(a, b, t_o) = setlistval(t_o, omul(B[a], B[b]))
|
|
|
|
|
2024-06-16 19:05:58 -05:00
|
|
|
: icmp(a, b, z) = { \\
|
|
|
|
B[a] = B[b] : equals -> 1 , \\
|
|
|
|
B[a] > B[b] : greater -> 1 , \\
|
|
|
|
B[a] < B[b] : less -> 1 \\
|
2024-02-01 17:00:28 -06:00
|
|
|
}
|
2023-11-15 20:01:35 -06:00
|
|
|
: irst(a, b, c) = equals -> 0, greater -> 0, less -> 0
|
|
|
|
: ield(addr, b) = setlistval(addr, equals)
|
|
|
|
: igld(addr, b) = setlistval(addr, greater)
|
|
|
|
: illd(addr, b) = setlistval(addr, less)
|
|
|
|
|
2024-02-01 17:00:28 -06:00
|
|
|
|
2023-11-15 20:01:35 -06:00
|
|
|
: ibe(addr, b, c) = {equals = 1 : ijmp(addr, 0, 0), jumped -> 1}
|
|
|
|
: ibne(addr, b, c) = {equals = 0 : ijmp(addr, 0, 0), jumped -> 1}
|
|
|
|
: ibg(addr, b, c) = {greater = 1 : ijmp(addr, 0, 0), jumped -> 1}
|
|
|
|
: ibl(addr, b, c) = {less = 1 : ijmp(addr, 0, 0), jumped -> 1}
|
|
|
|
|
|
|
|
: isto(v, addr) = setlistval(addr, v)
|
2024-03-24 18:50:55 -05:00
|
|
|
: imov(from, target) = setlistval(target, B[from])
|
2023-11-15 20:01:35 -06:00
|
|
|
|
|
|
|
# registers
|
|
|
|
# instruction pointer
|
|
|
|
: ip = 1
|
|
|
|
|
|
|
|
# is the result of icmp equal?
|
|
|
|
: equals = 0
|
|
|
|
|
|
|
|
# ditto for greater than
|
|
|
|
: greater = 0
|
|
|
|
|
|
|
|
# ditto for less than
|
|
|
|
: less = 0
|
|
|
|
|
|
|
|
# instruction loading areas
|
|
|
|
: inst = 0
|
|
|
|
|
|
|
|
# next three values after the instruction
|
|
|
|
: paramone = 0
|
|
|
|
: paramtwo = 0
|
|
|
|
: paramthree = 0
|
|
|
|
|
|
|
|
# main execution flows
|
2024-06-16 19:05:58 -05:00
|
|
|
: load(addr) = jumped -> 0, inst -> B[addr], \\
|
|
|
|
paramone -> B[addr + 1], \\
|
|
|
|
paramtwo -> B[addr + 2], \\
|
2023-11-15 20:01:35 -06:00
|
|
|
paramthree -> B[addr + 3]
|
2024-06-16 19:05:58 -05:00
|
|
|
: exec = { \\
|
|
|
|
inst = sto : isto(paramone, paramtwo), \\
|
|
|
|
inst = mov : imov(paramone, paramtwo), \\
|
|
|
|
inst = add : iadd(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = cmp : icmp(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = eld : ield(paramone, paramtwo), \\
|
|
|
|
inst = gld : igld(paramone, paramtwo), \\
|
|
|
|
inst = lld : illd(paramone, paramtwo), \\
|
|
|
|
inst = jmp : ijmp(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = be : ibe(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = bne : ibne(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = bg : ibg(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = bl : ibl(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = sub : isub(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = mul : imul(paramone, paramtwo, paramthree), \\
|
|
|
|
inst = div : idiv(paramone, paramtwo, paramthree) \\
|
2023-11-15 20:01:35 -06:00
|
|
|
}
|
|
|
|
: incip = {jumped = 0 : ip -> ip + instwidth[inst] + 1}
|
|
|
|
|
|
|
|
# execution occurs here
|
|
|
|
: execution = 0
|
|
|
|
: jumped = 0
|
|
|
|
|
|
|
|
: loop = {execution = 0 : execution -> 1, execution = 1 : execution -> 2, execution = 2 : execution -> 0}
|
|
|
|
: loopaction = {execution = 0 : load(ip), execution = 1 : exec, execution = 2 : incip}
|
2024-02-01 17:00:28 -06:00
|
|
|
: main = loopaction, loop
|
2023-11-15 20:01:35 -06:00
|
|
|
|
|
|
|
: sto = 1
|
2024-03-24 18:50:55 -05:00
|
|
|
: mov = 17
|
2023-11-15 20:01:35 -06:00
|
|
|
: add = 2
|
|
|
|
: cmp = 3
|
|
|
|
: eld = 4
|
|
|
|
: gld = 5
|
|
|
|
: lld = 6
|
|
|
|
: jmp = 7
|
|
|
|
: be = 8
|
|
|
|
: bne = 9
|
|
|
|
: bg = 10
|
|
|
|
: bl = 11
|
|
|
|
: sub = 12
|
|
|
|
: mul = 13
|
|
|
|
: div = 14
|
|
|
|
: rst = 15
|
|
|
|
|
2024-06-16 19:05:58 -05:00
|
|
|
: instwidth = [2,3,2,1,1,1,1,1,1,1,3,3,3,3,0,2,2]
|
2024-06-16 18:18:28 -05:00
|
|
|
"""
|