New 8-bit Processor

  • Schmolendevice
    6th Aug 2013 Member 0 Permalink

    For Ferne, try out 15 minus 9 which is 6. 15 in binary is 1111, 9 is 1001. Negative nine in two's complement (one's complement is the same thing as the number inverted) is equal to the number that needs to be added to the binary 9 in order to get zero with a carry. Any negative of a number is the number you add to it to get zero. The gimmick my cousin taught me was to invert the number to be negated and add it to one. NOT1001 is equal to 0110. If you add it now, you get 1111. So we add 1 to get 0 with a carry: 0111. 1001 + 0111 = 10000.

    Now add 1111 by the two's complement of 1001 (0111) and you get 0110, which is six in binary.

        111   Carry overs

        1111 15

    +  0111 -9

    =10110 +6 if the fifth bit is treated as a carry outside of the 4-bit integer.

     

    Then 9 minus 15, or 9 plus negative 15 is -6. So first we get the two's complement of 1111 = 0000 + 1 = 0001. So we have 1001 + 0001 = 1010. 1010 is the two's complement negative of 6  = 0110 = 1001 + 1 = 1010.

     

    I guess it's a matter of being able to visualize it. Also, I posted a save containing some simple registers an chips I made including a generally compact octal inverter.

  • Synergy
    6th Aug 2013 Member 0 Permalink

    Somewhat finished the design for my Binary > BCD program. Once all the RAM clearing commands are included, it should add up to like 101 instructions (fffffffuuuuuuu). I will probably increase the ROM limit to 127 instructions soon. Also this program uses variable reading from RAM. ie, RAM(B) -> A, or something like that. It's the same as what is already available for writing, just for reading from RAM. I will add this function to the processor soon.

     

    RAM(1): Holds initial value
    RAM(2-4): Holds the 3 BCD groups
    RAM(10): Holds RAM INDEX
    RAM(20): Holds outer loop
    RAM(30): Holds carry value
    RAM(40): Holds BCD shift/carry loop
    RAM(50): Holds BCD +3 loop

    INPUT > RAM(1)
    SET RAM INDEX(10): 2

    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    LOOP: repeats whole process 8 times
    -------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------
    gets carry and shifts initial value
    --------------------------------------
    SET RAM CARRY(30): 0
    RAM(1) > A
    10000000 > B
    AND AB > C
    C > A
    IF A==B
    SET RAM CARRY(30): 1

    RAM(1) > A
    RAM(1) > B
    ADD AB > RAM(1)
    ----------------------------------------
    loop: adds carries, gets carries and shifts all 3 BCD fields
    ----------------------------------------
    RAM INDEX(10) > B
    RAM(B) > A
    RAM(B) > B
    ADD AB > C
    C > A
    RAM CARRY(30) > B
    ADD AB > C
    C > A
    RAM INDEX(10) > B
    A > RAM(B)

    00010000 (16) > B
    AND AB > C
    C > A
    0 > RAM CARRY(30)
    IF A==B
    1 > RAM CARRY(30)
    RAM INDEX(10) > B
    RAM(B) > A
    00010000 > B
    XOR AB > C
    C > A
    RAM INDEX(10) > B
    A > RAM(B)

    RAM INDEX(10) > A
    00000001 > B
    ADD AB > RAM INDEX(10)
    RAM BCD LOOP(40) > A
    ADD AB > RAM BCD LOOP(40)
    RAM BCD LOOP(40) > A
    00000011 > B

    IF (A==B, else go back to start of this loop)
    leave this loop;
    /loop end

    ----------------------------------------------------------


    2 > RAM INDEX(10)


    RAM OUTER LOOP(20) > A
    00000111 > B
    IF (A==B, else, continue onwards)
    JUMP TO END OF PROGRAM;

    --------------------------------------------------------------------------------
    loop: checks each BCD field if they are 5 or more, and adds 3
    ---------------------------------------------------------------------------------

    RAM INDEX(10) > B
    RAM(B) > A
    00000011 > B
    ADD AB > C
    C > A
    00001000 > B
    AND AB > C
    C > A
    IF (A==B)
    RAM INDEX(10) > B
    RAM(B) > A
    00000011 > B
    ADD AB > C
    C > A
    RAM INDEX(10) > B
    A > RAM(B)

    RAM INDEX(10) > A
    00000001 > B
    ADD AB > RAM INDEX(10)
    RAM BCD LOOP2(50) > A
    ADD AB > RAM BCD LOOP2(50)
    RAM BCD LOOP2(50) > A
    00000010 > B
    IF (A==B, else go back to start of loop)
    leave this loop;

    /loop end
    ----------------------------------------------------------------

    2 > RAM INDEX(10)
    0 > RAM BCD LOOP(40)
    0 > RAM BCD LOOP2(50)
    RAM OUTER LOOP(20) > A
    00000001 > B
    ADD AB > RAM OUTER LOOP(20)
    RAM OUTER LOOP(20) > A
    00001000 > B
    IF (A==B, else go back to start of loop)
    leave this loop;


    //loop end
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    OUTPUT > RAM(2)
    OUTPUT > RAM(3)
    OUTPUT > RAM(4)

     

     

    Funniest thing is. The program will probably take a little over 1.5 hours to complete (about 1500 instructions after all the loops). 60fps yields about 20 instructions per minute.

     

    EDIT: Added the two new data flow operations:

     

    RAM(B) -> A (reads from RAM, stores in A. B is used as address)

    RAM(B) -> B (reads from RAM, stores in B. B is used as address)

     

    Instructions are added to the front page post.

     

    EDIT 2: Increased ROM size 16%. Now supports 116 instructions.

     

    EDIT 3: Created a program helper. This should make it far easier to make programs (rather than placing INWR pixels everywhere). Hopefully I haven't mixed any of the wires up. I'll know by tomorrow if there is.

     

     

    Remember, once you have finished, drag a box of C4 over the INWR, copy it, paste it into the diamond box, wait for the BRAY to dissapear and then fill the holes with INWR. When you have done that, blow it up (with fire or something) and then copy/paste the INWR into the blue template.

    Edited 5 times by Synergy. Last: 6th Aug 2013
  • Ferne
    7th Aug 2013 Member 0 Permalink
    The program helper is cool but I like making these programs manually, without an assembler or helpers.
  • Synergy
    7th Aug 2013 Member 0 Permalink

    Yeah it does feel better to do it by hand sometimes.

     

    In other news. I have finally achieved what I set out to achieve by making this computer in the first place. And that is successfully implementing the double dabble algorithm (converts binary to BCD, which is essentially converting it to decimal).

     

    http://en.wikipedia.org/wiki/Double_dabble

     

    I believe I was the first to implement double dabble via hardware, and now I have become the first to implement it via software.

     

    Be warned though, this program takes about 1.5 hours to complete at 60fps.

     

     

    Here's a video at 10x speed.

     

     

    Going to look into adding A > B and A < B now.

    Edited once by Synergy. Last: 9th Aug 2013
  • jinoh
    22nd Aug 2013 Member 0 Permalink

    @Synergy (View Post)

     You don't really should implement subtraction, because we can just add -10 to subtract 10. Yeah, in this case -10(11110110) is inverted bits of 9(00001001). Calculate 00001111(15) + 11111110(-2) and it would be 13 as the overflow (over these 8 bits) would be cut down.

  • mniip
    22nd Aug 2013 Developer 0 Permalink
    @jinoh (View Post)
    that's jsut how subtraction works inside, it's nice to have it as an opcode
  • china-richway2
    23rd Aug 2013 Member 0 Permalink

    @Synergy (View Post)

     Very good. I'm going to translate it into my instructions.

     

    EDIT: Too many instructions?

    Edited once by china-richway2. Last: 23rd Aug 2013
  • Synergy
    23rd Aug 2013 Member 0 Permalink

    It's about 97 instructions long in the end. Also my RAM doesn't clear automatically. Therefore I needed to use a seperate clear instruction whenever I wrote to RAM. So you might be able to make it about 80 instructions if your RAM clears automatically when writing.

     

    Let me know if you have any questions china-richway2. If you don't understand anything I can explain it for you. The method in my previous post was just my draft. Although it happened to be a perfect draft that worked flawlessly the first time I tried it lol. Will be cool to see this program working on your processor too.

     

    Edited 2 times by Synergy. Last: 23rd Aug 2013
  • china-richway2
    24th Aug 2013 Member 0 Permalink

    @Synergy (View Post)

    Probably because I forgot some instructions in my processor (lol)

    Compare instructions is not easy for my processor. This is the reason I failed to make it. I'll try again later.

  • Ferne
    6th Sep 2013 Member 0 Permalink
    Why did this die? ;_; This was so awesome...