Quad-Instruction FILT Computer

  • 64_Tesseract
    15th May 2021 Member 2 Permalink

    The purpose of this thread is to over-explain my latest save "Quad-Instruction FILT Computer" [2714304].

     

    The Basics

    This computer is based on a minimal CPU instruction set presented in this video.

    In essence, it explains how you can perform different operations with just subtraction: you can add by first inverting a number and subtracting that; you can set a memory position to 0 by subtracting it from itself; etc.

    The video used a single command, which subtracted and compared the number in the same command; however I felt it would be too slow to subtract and check if it's less than 0 for every single command. I also didn't have enough room in a single FILT to store 3 RAM positions, and I wasn't sure how one sent characters to STDOUT by subtracting from a virtual register, so I settled on having 4 commands rather than a single over-complicated one.

    You may have noticed there is only one storage block in the computer; this is because the code shares the space with variables. This means the computer can modify its own program, but it can also start executing unintentional commands if the programmer is not careful. Make sure you distinctly separate your code and your variables and constants after it so the computer does not parse raw numbers.

    The computer begins by reading value 0 (the top-right most pixel) and tries to parse it; the 3 segments, "addr A", "addr B", and "mode", are stored, and depending on the "mode" it will utilize both addresses in different ways. Finally, unless it goes to another address, it will move onto the next value and parse it.

     

     

    Commands

    Set Value

    Compiler command: set [number]

    Sets the value of the line it's on to the raw number it is given. All commands in the compiler work in the same way, by setting the line/pixel they're on to the result of a formula.

     

    Subtract

    Compiler command: sub [a] [b]

    Subtracts the value in address [a] from the one in address [b], and puts the result back in [a].

    The following example will add 5 to 6:

        sub 2 1

        set -5

        set 6

     

    Goto

    Compiler command: goto [a] [b]

    If the value in address [a] is less than or equal to 0, the computer will continue execution at address [b]. Otherwise, it will continue to the next command in memory after the Goto command.

    The following example will skip the second instruction and subtract 8 from 6; if set 0 were setting a positive number, it will set the 6 to 0 and hence not modify the 8:

        goto 3 2

        sub 5 5

        sub 5 4

        set 0

        set 8

        set 6

     

    Print

    Compiler command: print [a]

    Sends the value in [a] via BRAY to the print line, to the left of the computer. Different modules may utilize this information differently.

    The following example will print the result of 3 - 2 if the Hex 7-Seg display module is attached:

        sub 2 3

        print 2

        set 3

        set 2

     

    Read

    Compiler command: read [a]

    Requests an input from the input module attached by sending a BRAY signal, and sets the value of [a] to the ARAY received.

    The following example will add 2 user-provided numbers and print the result:

        read 5

        read 6

        sub 7 6

        sub 5 7

        print 5

        set 0

        set 0

        set 0

     

     

    LUA Compiler
    I have modified my previous computer's LUA compiler to work with this computer's commands, at https://pastebin.com/jpNMTA4r. After running dofile("PATH-TO-SCRIPT") in the console, replacing PATH-TO-SCRIPT with the full directory to the program, you will be prompted to enter a directory to a FILT Computer script. After hitting enter, click on the top-right white-coloured FILT of the memory block that is sticking out to paste the compiled program in the correct location. To start the program, ensure all necessary modules are attached, and SPRK the button labelled "RUN CODE".

    As with the previous compiler, there are labels the compiler can insert into the program automatically. This can be used as goto locations that stay constant as code is added or removed behind it, or to store variable names rather than raw line numbers. All instances of [TEXT] are replaced with the line number of code with (TEXT) placed at the end of the line, where "TEXT" is an alphanumeric string.

    For example, in the following script, if you were to look at the processed code you would see that [start] has been replaced with 0, [count] with 3, and so on:
        sub [count] [inc] (start)
        goto [count] [start]
        set 5 (inc)
        set 12 (count)

     

    Lines not beginning with any of the aforementioned commands are completely ignored - this means your script can have comments, or if your text editor supports it, collapsable sections of code by using brackets. Note that a tag by itself, for instance a line with only (tag) and no valid code, will not replace instances of [tag] with its line number.

    Edited once by 64PBRB. Last: 15th May 2021
  • random_rickroll
    18th May 2021 Member 0 Permalink

    @64PBRB (View Post)

     how should i print text?