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.
File | Demo | Description |
master.sico | All libraries in one file. | |
string.sico | demo | String operations, printing, formating. |
uint.sico | demo | Unsigned integer arithmetic and bitwise operations. |
int.sico | Signed comparisons, mul, and div. | |
random.sico | demo | Pseudo-random number generator. |
memory.sico | demo | Memory allocation, copying, etc. |
graphics.sico | demo | 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:
The example can be broken up into a few parts:
0 ? string.print | the 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:
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
All of the functions are fairly well optimized. The table below gives the worst case number of instructions required per function call.
Function | Time (64 bits) |
write | 2303 |
read | 1456 |
cmp | 29 |
min | 34 |
max | 34 |
set | 24 |
neg | 25 |
add | 30 |
sub | 31 |
mul | 885 |
div | 613 |
gcd | 1330 |
shl | 168 |
shr | 543 |
not | 26 |
and | 485 |
or | 486 |
xor | 487 |
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.
Function | Time (64 bits) |
write | 2317 |
read | 1472 |
cmp | 37 |
min | 43 |
max | 43 |
abs | 30 |
mul | 893 |
div | 640 |
shr | 555 |
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:
For instance, to get a random number modulo 52 and store it in rand, call:
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.
For instance, to allocate a block of memory with 30 cells and set arr[2]=400:
demo_memory.sico shows how to use the library. It's also used in the live version linked above.