SICO Libraries

These are the libraries I've worked on to build SICO up from one instruction into an easy to use architecture.

They can all be downloaded in sico.zip.

FileDemoDescription
master.sicoAll libraries in one file.
string.sico demo String operations, printing, formating.
uint.sico demo Unsigned integer arithmetic and bitwise operations.
int.sicoSigned comparisons, mul, and div.
random.sico demo Pseudo-random number generator.
memory.sicodemo Memory allocation, copying, etc.
graphics.sicodemo Image drawing. Still in testing.

Strings

Try the live demo here.

string.sico is fundamental to working on other libraries. It defines the print function which allows us to print ASCII strings as well as numerical values. This is needed to print diagnostic messages and see what other libraries are actually doing. It can be called like this:

0 ? string.print 'x ' '= ' string.uint x 10 0

The example can be broken up into a few parts:

0 ? string.printthe SICO instruction that jumps to the string.print function and gives it our calling address.
'x ' '= ' the ASCII literal values for "x = ". We could also use 120 32 61 32
string.uint a special value that tells string.print that the next value is an unsigned integer.
x the unsigned integer to output.
10 the ASCII value for an end-of-line.
0 the end of the string.

So if [x] is 20, then this will get output to the console:

x = 20

demo_string.sico shows how to use the library. It's also used in the live version linked above.

Unsigned Math

Try the live demo here.

uint.sico defines all of the usual functions for handling unsigned integer arithmetic and bitwise operations. For example, to compute the bitwise AND of [B] and [C] and store it [A], we would call

0 ? uint.and A B C

All of the functions are fairly well optimized. The table below gives the worst case number of instructions required per function call.

FunctionTime (64 bits)
write2303
read1456
cmp29
min34
max34
set24
neg25
add30
sub31
mul885
div613
gcd1330
shl168
shr543
not26
and485
or486
xor487

demo_uint.sico shows how to use the library. It's also used in the live version linked above.

Signed Math

int.sico covers all of the signed integer functions that uint.sico doesn't cover. The table below gives the worst case number of instructions required per function call.

FunctionTime (64 bits)
write2317
read1472
cmp37
min43
max43
abs30
mul893
div640
shr555

Random Number Generation

Try the live demo here.

random.sico defines a PRNG with a period of 2^64. It provides five functions for handling random numbers:

random.hash ret num random.seed num random.jump num random.get dst random.mod dst mod random.shuffle arr len

For instance, to get a random number modulo 52 and store it in rand, call:

0 ? random.get rand mod rand: 0 mod: 52

demo_random.sico shows how to use the library. It's also used in the live version linked above.

Memory

Try the live demo here.

memory.sico defines functions for managing and allocating memory. In order to allocate memory safely, the library needs to be last when concatenating with other libraries.

mem.getargs dst0 refs0 dst1 refs1 ... 0 mem.get val mem mem.getidx val mem idx mem.set mem val mem.setidx mem idx val mem.zero dst len mem.copy dst src len mem.sort arr len cmp mem.alloc mem len mem.realloc ret mem len mem.free mem mem.alloc.verifyfree

For instance, to allocate a block of memory with 30 cells and set arr[2]=400:

0 ? mem.alloc arr len 0 ? mem.set arr idx val 0 ? mem.free arr arr: 0 len: 30 idx: 2 val: 400

demo_memory.sico shows how to use the library. It's also used in the live version linked above.