MEGALITER BYTE CODE Data types 0000: byte 0001: int 0010: float (4 byte) 0011: generic address 0100: byte array (IE: text) 0101: int array 0110: float array 0111: generic address array 1000: address to byte 1001: address to int 1010: address to float 1011: address to generic address 1100: address to byte array 1101: address to int array 1110: address to float array 1111: address to generic address array The first 2 bytes of any array will determine the length of the array. Command syntax [1 byte command name] [1 or 2 byte arg types?] [arg?] [arg?]... Data will either be stored in the stack or the heap. The stack contains statically allocated scopes. The heap contains dynamically allocated memory. Relative address ranges 0 to 16383: program code. 16384 to 32767: bottom level (global) scope. 32768 to 49151: top level (current) scope. 49152 to 65535: heap. Organization of core memory [program code] [resource?] ... [resource?] [bottom scope] ... [top scope] [buffer] [heap] Command list 0 = loadNextOneArgument [arg]: Load arguments to be used in the next command. 1 = loadNextTwoArguments [arg] [arg] 2 = loadNextThreeArguments [arg] [arg] [arg] 3 = loadNextFourArguments [arg] [arg] [arg] [arg] 4 = setCurrentScopeSize [size] 5 = set [dest] [value]: Store a value. 6 = add [dest] [num] [num] 7 = subtract [dest] [num] [num] 8 = multiply [dest] [num] [num] 9 = divide [dest] [num] [num] 10 = modulus [dest] [num] [num] 11 = equal [dest] [value] [value]: Type is cast to that of the first value. 12 = notEqual [dest] [value] [value] 13 = greater [dest] [num] [num] 14 = less [dest] [num] [num] 15 = and [dest] [num] [num] 16 = or [dest] [num] [num] 17 = not [dest] [num] 18 = booleanNot [dest] [num] 19 = increment [dest]: Add 1 to a number. 20 = decrement [dest]: Subtract 1 from a number. 21 = increase [dest] [num]: Add the given amount to a number. 22 = decrease [dest] [num]: Subtract the given amount from a number. 23 = absoluteValue [dest] [num] 24 = raiseToPower [dest] [num] [num] 25 = squareRoot [dest] [num] 26 = sine [dest] [num] 27 = cosine [dest] [num] 28 = tangent [dest] [num] 29 = random [dest] [minimum] [maximum] 30 = jump [commandAddress]: Move execution to an address relative to the current resource. 31 = jumpIf [commandAddress] [num] 32 = jumpIfNot [commandAddress] [num] 33 = pushSubroutineArgument [value]: Add an argument for the next subroutine to call. 34 = jumpToSubroutine [commandAddress] 35 = jumpToSubroutineAndStoreOutput [dest] [commandAddress] 36 = return 37 = returnWithValue [value] 38 = quit: Abort the program. 39 = convertLocalAddressToGlobalAddress [dest] [address] 40 = getArrayLength [dest] [array] 41 = setArrayLength [dest] [num] 42 = getArrayElement [dest] [array] [index] 43 = setArrayElement [dest] [index] [value] 44 = findArrayElement [dest] [array] [value] 45 = pushArrayElement [dest] [value] 46 = concatenateArray [dest] [array]: Append the elements of one array onto another. 47 = getSubarray [dest] [array] [index] [index] 48 = findSubarray [dest] [array] [array] 49 = convertTextToNumber [dest] [text] 50 = convertNumberToText [dest] [num] 51 = allocateHeapMemory [dest] [size]: Reserve memory in the heap and stores a single byte handle in dest. 52 = deallocateHeapMemory [heapHandle] 53 = getHeapMemoryAddress [dest] [heapHandle] 54 = getHeapMemorySize [dest] [heapHandle] 55 = setHeapMemorySize [heapHandle] [num] 56 = sendDebugValue [value] 57 = promptDebugValue [dest] 58 = drawText [posX] [posY] [text] 59 = drawBar [posX] [posY] [width] [color] 60 = drawImage [posX] [posY] [width] [data] 61 = clearWindow 62 = getKey [dest]: Store value of last pressed key. Store 0 if no key was pressed. 63 = promptValue [dest] 64 = getTime [dest] 65 = sleep [num] 66 = readSharedMemory [dest] [index] 67 = writeSharedMemory [index] [value] 68 = getNumberOfAllocatedCores [dest] 69 = getCurrentCoreIndex [dest] 70 = getNumberOfFiles [dest] 71 = getFileName [dest] [which] 72 = createFile [dest] [name] [size] [type]: Store a single int handle in dest. 73 = openFile [dest] [name]: The handle will be -1 if the file was not found. 74 = readFile [dest] [fileHandle] [index] [amount] 75 = eraseFile [fileHandle]: Necessary if the mass storage device is flash memory. 76 = writeFile [fileHandle] [index] [value] 77 = getFileSize [dest] [fileHandle] 78 = getFileType [dest] [fileHandle] 79 = deleteFile [fileHandle] 80 = runFile [coreAmount] [fileHandle] 81 = includeFile [fileHandle]: Dynamically load executable code and store address of resource in dest. 82 = excludeFile [fileHandle]: Deallocate space reserved for code resource. 83 = jumpToIncludedSubroutine [fileHandle] [commandAddress] 84 = jumpToIncludedSubroutineAndStoreOutput [dest] [fileHandle] [commandAddress] Test code Store a byte: 0000: 05 80 40 00 56 Add: 0000: 06 80 00 40 00 03 02 Store byte then add: 0000: 05 80 40 00 09 0005: 06 80 80 40 01 04 00 10 Divide: 0000: 09 80 00 40 00 48 02 Greater: 0000: 0D 80 00 40 00 0A 05 Or: 0000: 10 80 00 40 00 20 02 Increase: 0000: 05 80 40 00 06 0005: 15 80 40 00 07 Raise to power: 0000: 18 80 00 40 00 03 02 Jump: 0000: 05 80 40 00 00 0005: 13 80 40 00 0009: 1E 30 00 05 Subroutine: 0000: 04 00 08 0003: 21 00 03 0006: 23 83 40 00 00 0D 000C: 26 000D: 05 80 80 00 56 0012: 07 88 00 80 01 80 00 02 001A: 25 80 80 01 Store an address: 0000: 05 B3 40 00 40 03 Load next argument: 0000: 05 B3 40 00 40 03 0006: 01 B0 40 00 07 000B: 05 80 Store an int: 0000: 05 91 40 00 00 03 Square root of int: 0000: 19 91 40 00 01 90 To inspect a float as a series of unsigned characters: float f = 5; unsigned char *c = reinterpret_cast(&f); http://stackoverflow.com/questions/1723575/how-to-perform-a-bitwise-operation-on-floating-point-numbers var buffer = new ArrayBuffer(4); var intView = new Int32Array(buffer); var floatView = new Float32Array(buffer); floatView[0] = Math.PI console.log(intView[0].toString(2)); //bits of the 32 bit float Convert byte to float: 0000: 05 A0 40 00 05 Sine: 0000: 1A A2 40 00 40 A0 00 00 Store an array: 0000: 05 C4 40 00 00 02 08 09 Get array length: 0000: 28 84 40 00 00 02 08 09 Set array length: 0000: 05 C4 40 00 00 02 08 09 0008: 29 C0 40 00 03 Get array element: 0000: 05 C4 40 00 00 03 08 09 55 0009: 2A 8C 00 40 08 40 00 01 Set array element: 0000: 05 C4 40 00 00 03 08 09 55 0009: 2B C0 00 40 00 01 04 Find array element: 0000: 05 C4 40 00 00 03 08 09 55 0009: 2C 8C 00 40 08 40 00 55 Push array element: 0000: 05 C4 40 00 00 03 08 09 55 0009: 2D C0 40 00 16 Concatenate array: 0000: 05 C4 40 00 00 03 08 09 55 0009: 2E C4 40 00 00 02 11 12 Get subarray: 0000: 05 C4 40 00 00 05 08 09 55 11 12 000B: 2F CC 00 40 08 40 00 01 03 Equal using arrays: 0000: 0B 84 40 40 00 00 02 93 28 00 02 93 28 Find subarray: 0000: 30 84 40 40 00 00 05 08 09 55 11 12 00 02 55 11 Convert text to number: 0000: 31 84 40 00 00 02 31 34 Convert number to text: 0000: 32 C0 40 00 99 Allocate heap memory: 0000: 33 80 40 00 05 0005: 33 80 40 01 08 Deallocate heap memory: 0000: 33 80 40 00 05 0005: 34 80 40 00 0009: 33 80 40 01 08 Get heap memory address: 0000: 33 80 40 00 05 0005: 33 80 40 01 08 000A: 35 B8 40 03 40 01 Set heap memory size: 0000: 33 80 40 00 05 0005: 33 80 40 01 08 000A: 37 80 40 00 10 Send debug value: 0000: 38 00 71 0003: 38 40 00 06 42 55 54 54 45 52 Prompt debug value: 0000: 39 C0 40 00 0004: 38 40 00 03 41 42 43 First test program: 0000: 38 40 00 06 48 45 4C 4C 4F 0A 000A: 26 Second test program: 0000: 38 40 00 05 4E 55 4D 3F 0A 0009: 39 C0 40 00 000D: 31 8C 40 10 40 00 0013: 08 88 00 40 11 40 10 02 001B: 32 C8 40 20 40 11 0021: 38 C0 40 20 0025: 26