Fastest possible computer created!

  • RockerM4NHUN
    8th Aug 2014 Member 17 Permalink

     


    ********************
    ** Introduction **
    ********************
    I've created a computer that processes a command in 8 frames (max speed of electronic wires).
    It relies on pipeline system: generating next address | reading program from ROM | executing command
    These three parts done at the same time.
    Computer:


    Compiler:

    The computer has 3 main parts that separates in function:
    - Controller part: Sends clock signs, calculates next address, reads program lines.
    - Register part: Stores data and reads it with very high speed.
    - ALU part: Does the trick. It handles the commands and data. The memory is treated like a normal ALU function.
    The computer has 2 custom registers, 1 status register and 128 bytes of memory.
    (The computer is byte orientated.)
    --------------------------------------
    |Every address pattern starts with 0!|
    --------------------------------------

    *************
    ** Usage **
    *************

    Run default program:
    - Turn on the computer (green button at right)
    - Use the (decimal) number keypad, to select the program you want:
    --- 0: Stop
    --- 1: COM guess your number
    ------- Think of a number, less than 256
    ------- If the guess was right click "YES", otherwise "NO"
    ------- Then if the guess is higher than your number click "YES"
    ------- If it says "666", then you lied!
    --- 2: Fibonacci sequence

    --- 3: Sample program 1

    --- 4: Sample program 2
    - Press OK (always after number input)
    - TADAAAAM!

    Run custom program:
    - Write your program in mnemonics, then translate it into binary (useful, to do things this way)
    - Clear the program memory, then paste your program there
    - Start computer

    ARAY means 1 !!!

    ***
    *** Sample program 1: Simple adder
    ***
    Program adds two numbers, from input, then displays the result.

    Mnemonics:
    NIN A (Read first number from input)
    NIN B (Read second number from input)
    ADD A, B (Add the two numbers, result to A)
    OUT A (Display the result)
    STOP

    Binary:
    00100 01 00 00000000
    00100 10 00 00000000
    01001 01 10 00000000
    10100 01 00 00000000
    00000 00 00 00000000

    ***
    *** Sample program 2: Odd counter
    ***
    Program asks for numbers, while it not gets zero, then tells how many numbers were stored to memory. Finally displays number of odds.
    (I wrote the prog this way, to show some memory handling, and conditional jumps.)

    Mnemonics:
    SYSR (Clear memory)
    "InputLoop" - NIN A (Ask for number)
    IFN A, 0xFF (If number equals zero)
    JMP 0x07 (= "Testing", No more numbers will come)
    STO A, B (Else store the number)
    ADD B, 0x01 (Increment address)
    JMP 0x02 (= "InputLoop")
    "Testing" - OUT B (Display how many numbers were stored)
    "TestLoop" - IFN B, 0xFF (If item counter equals zero)
    JMP 0x13 (= "End", program stops)
    ADD B, 0xFF (= -1)
    LOD A, B (Load item)
    STO B, 0x7F (Store item counter)
    LOD B, 0x7E (Load odd counter)
    IF A, 0x01 (IF item is odd)
    ADD B, 0x01 (Increment odd counter)
    STO B, 0x7E (Store odd counter)
    LOD B, 0x7F (Load item counter)
    JMP 0x08 (= "TestLoop")

    "End" - LOD A, 0x7E (Load result)

    OUT A (Display result)

    STOP

     

    Binary:
    10111 00 00 00000000
    00100 01 00 00000000
    00011 01 00 11111111
    00001 00 00 00000111
    01011 01 10 00000000
    01001 10 00 00000001
    00001 00 00 00000010
    10100 10 00 00000000
    00011 10 00 11111111
    00001 00 00 00010101
    01001 10 00 11111111
    01010 01 10 00000000
    01011 10 00 01111111
    01010 10 00 01111110
    00010 01 00 00000001
    01001 10 00 00000001
    01011 10 00 01111110
    01010 10 00 01111111
    00001 00 00 00001000

    01010 01 00 01111110

    10100 01 00 00000000
    00000 00 00 00000000

    ************
    ** Code **
    ************
    Code lines are 15 bits wide
    CCCCCXXYYDDDDDDDD
    C: Command bits
    X: First operand selector
    Y: Second operand selector
    D: Constant data
    Operands (X and Y):
    0 - constant data (D bits)
    1 - A register
    2 - B register
    3 - Status register
    If there is a result, it will be stored to the first operand.
    Status reg or constant: no store
    A or B: overwrite existing data
    Status:
    0 - Carry
    1 - op1>op2
    2 - op1=op2
    3 - op2=0
    4 - op1=0
    5 - LIN result = "NO"
    6 - unused (0)
    7 - unused (0)

    ****************
    ** Commands **
    ****************
    0xYY - COM op1, op2
    op1 and op2 can be constant data, or a register
    0x00 - Stop
    0x01 - JMP addr | Jumps to the specified program line
    0x02 - IF data, mask | Makes bitwise AND with data and mask, if the result is zero the next command will be skipped.
    0x03 - IFN data, mask | Makes bitwise AND with data and mask, if the result is not zero the next command will be skipped.
    0x04 - NIN dest | Number input, stores result into dest.
    0x05 - COPY dest, source | Copies soureces data into dest.
    0x06 - LIN | Logical input (yes/no), stores result into status<5> (mask: 0x20).
    0x07 - RND dest | Randomizes a number, and stores it into dest.
    0x08 - ADC data, data | See ADD (0x09) + adds the status<0> carry bit (mask: 0x01).
    0x09 - ADD data, data | Adds the two numbers, result will be stored in first operand. Also sets the status<0> carry bit (mask: 0x01) if the result was bigger than 255.
    0x0A - LOD dest, addr | Reads the addr'th byte of memory and stores into dest.
    0x0B - STO data, addr | Writes the data into the addr'th byte of memory.
    0x0C - AND data, data | Makes bitwise AND, stores the result into first operand.
    0x0D - OR data, data | Makes bitwise OR, stores the result into first operand.
    0x0E - XOR data, data | Makes bitwise XOR, stores the result into first operand. XOR with 0xFF means bitwise NOT. (So not function not implemented into the hardware.)
    0x10 - SHR data, num | Shifts right data with "num" bits. Result will be stored into first operand. SHR 0xDF, 2 result: 0x37
    0x11 - SHL data, num | Shifts left data with "num" bits. Result will be stored into first operand. SHL 0xDF, 2 result: 0x7C
    0x12 - RTR data, num | Shifts right data with "num" bits. Result will be stored into first operand. RTR 0xDF, 2 result: 0xF7
    0x13 - RTL data, num | Shifts left data with "num" bits. Result will be stored into first operand. RTL 0xDF, 2 result: 0x7F
    0x14 - OUT low, high | Outputs number, only the 2 lower bits of high matters. Because of speed issues, at least 3 other commands have to be between two OUT commands, or 1 jump.
    0x15 - STIP | Stores the code address of itself to A register.
    0x16 - TEST | Sets status<1> if op1 > op2, sets status<2> if op1 == op2, sets status<3> if op2 = 0, sets status<4> if op1 = 0
    0x17 - SYSR | Resets memory, registers and output.
    0x18 - NEG dest, data | Generates the twos complement of data and stores it to dest.
    0x1F - NOP

    Edited 7 times by RockerM4NHUN. Last: 12th Aug 2014
  • iamdumb
    8th Aug 2014 Member 1 Permalink

    Wow, how on Earth does that ALU work.

  • dom2mom
    8th Aug 2014 Member 6 Permalink

    Marry me and be done with it.

  • RockerM4NHUN
    9th Aug 2014 Member 0 Permalink

    @iamdumb

    The ALU in a nutshell:

    1. The command code turns power on at the choosen ALU part

    2. The control signal and the data will only reach the choosen hardware

    3. It generates result or does something (with VERY VERY precise timing)

    4. The speciallly built registers allows the machine, to write and read the result in the same frame, so the next operation will get the right data

  • Ferne
    10th Aug 2014 Member 0 Permalink

    I am writing a calculator program and the thing I'm trying to do now is multiplication. I have problems with a loop though, can't seem to use TEST and IF properly...

  • RockerM4NHUN
    12th Aug 2014 Member 0 Permalink

    Could you figure out the problem? Or i have to help?

  • Ferne
    13th Aug 2014 Member 0 Permalink

    Either I am doing something wrong, or the computer is bugged. I'm trying to do a subtraction program. Take a look:

    NIN 2 0 0

    NIN 1 0 0

    XOR 1 0 0xFF

    ADD 1 0 1

    ADD 2 1 0

    OUT 1 0 0

     

    Should work, I get the complement of A register (NOT and +1) and add it to B, but it doesn't. Gives out weird results. Sometimes it seems the result is inverted (5 - 3 = 253) but sometimes... 8 - 3 = 253 too. Sometimes it's 254, sometimes weird stuff. When I invert the result, the result is usually close to the correct answer, but it's not exact, for example I tried 86 - 40 and it gave me 39. Is it a bug in my program?

    Edited once by Ferne. Last: 13th Aug 2014
  • RockerM4NHUN
    13th Aug 2014 Member 0 Permalink

    The problem is that your ADD result is in 2, but you display 1.

    You can also generate twos complement with instruction NEG

    The weird results came from, that you displayed the complement of the substractant.

    Edited 3 times by RockerM4NHUN. Last: 13th Aug 2014
  • ISproductions
    13th Aug 2014 Member 0 Permalink

    blown away

  • RockerM4NHUN
    13th Aug 2014 Member 0 Permalink

    I wrote a multiplication program, do you want me to post it?