I'm doubling the memory of my CPU to 16 bytes, and I want to make some more videos to show what it can do. I have one program to run on it in a video, and I'm looking for another one. Does anyone want to write a program to go in the video? I'll post some instructions below, and if I get any responses I might use one. By the way, this post is likely to change as the CPU changes and people tell me what I've done wrong. :biggrin.gif:
EDIT: There are no inputs at the moment, apart from loading code in, and the output is just a row of 8 redstone torches to show a single byte of output, so programs have to just run through themselves for now without further input. :smile.gif:
This is how it works:
The CPU starts at memory location 0. When it runs, it reads the op code at its current location, then it does that operation on whatever the next byte is. Here are the op codes:
0 NOT (NOT)
1 - memory (SUBm)
2 + memory (ADDm)
3 OR memory (ORm)
4 WRITE memory (STOREm)
5 BRANCH if Accumulator = 0 (BEQ)
6 AND memory (ANDm)
7 LOAD memory (LOADm)
8 ---UNUSED---
9 - constant (SUBi)
10 + constant (ADDi)
11 OR constant (ORi)
12 WRITE out (OUT)
13 BRANCH unconditionally (BRA)
14 AND constant (ANDi)
15 LOAD constant (LOADi)
Example:
If the first two bytes contain 15 30, then the CPU will do operation 15 (load) and load the value 30. If the next two bytes are 10 12, then it'll do operation 12 (add), and add 12 to whatever is already stored in the CPU, which is 30. The result, 42, is stored in the CPU.
The operations on constants use whatever the next byte is to do the operation. The operations on memory use the next byte as the memory address of the value to use.
Example:
07 05 Will load whatever is in memory location 05.
Branching moves the program to the memory location that follows.
Example:
13 10 Will move the program [s]to memory location 10[/s] forward by 10, and continue from there.[/s]
15 01 10 02 13 -5 would load 1, add 2, then go back to the beginning, by shifting back by 5.
Here's a sample program that calculates 1+2+3+... indefinitely, outputting after each addition.
ok, i haven't yet implemented the collision-code but I made this prog, for your REAL pc^^.
Basically it is just an editor with a function to "compile" the code to numbers.
It also counts used memory etc, and can autocreate a post nad so on.
By coloring the source-code you can find out where your mistakes are # are comments.
Try it if you want. I think it's making programming easier.
I've been working on and off these past days on a integrated developer environment for this CPU, and I'm finally finished. It contains an assembler with support for variables and labels, memory display (with import/export) and interpreter.
You can download it here. Note that you need .NET 4.0 to run it.
0 NOT
1 - memory
2 + memory
3 OR memory
4 WRITE memory
5 BRANCH if Accumulator = 0
6 AND memory
7 LOAD memory
8 NOT
9 - constant
10 + constant
11 OR constant
12 WRITE out
13 BRANCH unconditionally
14 AND constant
15 LOAD constant
Need to write that table better.
I assume your CPU has only one register (the accumulator or A)
Addressing modes are then
Instruction mem
Instruction immediate
A is accumulator
PC is program counter
OP is the following operand
MEM is the memory location specified by the following operand
0 NOT (NOT A->A)
1 SUBMEM (A-MEM->A)
2 ADDMEM (A+MEM->A)
3 ORMEM (A OR MEM->A)
4 WRITE (A->MEM)
5 BRANCHZERO (IF flag zero set then OP->PC)
6 ANDMEM (A AND MEM->A)
7 LOAD (MEM->A)
8 NOT (How is this different to 0?)
9 SUBIMM ( A-OP->A)
10 ADDIMM ( A-OP
11 ORIMM ( A OR OP -> A)
12 WRITE out (Don't understand this opcode)
13 BRANCHALWAYS ( OP->PC )
14 ANDIMM ( A AND OP -> A)
15 LOAD constant (how can you load a constant? or are you using another register called constant)
A is accumulator
PC is program counter
OP is the following operand
MEM is the memory location specified by the following operand
0 NOT (NOT A->A)
1 SUBMEM (A-MEM->A)
2 ADDMEM (A+MEM->A)
3 ORMEM (A OR MEM->A)
4 WRITE (A->MEM)
5 BRANCHZERO (IF flag zero set then OP->PC)
6 ANDMEM (A AND MEM->A)
7 LOAD (MEM->A)
8 NOT (How is this different to 0?)
9 SUBIMM ( A-OP->A)
10 ADDIMM ( A-OP
11 ORIMM ( A OR OP -> A)
12 WRITE out (Don't understand this opcode)
13 BRANCHALWAYS ( OP->PC )
14 ANDIMM ( A AND OP -> A)
15 LOAD constant (how can you load a constant? or are you using another register called constant)
Thanks, that looks much better. 0 NOT and 8 NOT do the same thing, one of them is a spare instruction, I haven't found anything to do with it yet. 12 writes to a register that I'm going to use as an output to a screen. At the moment it doesn't use OP, but I plan on using that as well eventually. 15 does OP->A.
Thanks, that looks much better. 0 NOT and 8 NOT do the same thing, one of them is a spare instruction, I haven't found anything to do with it yet. 12 writes to a register that I'm going to use as an output to a screen. At the moment it doesn't use OP, but I plan on using that as well eventually. 15 does OP->A.
OK trying to simplify it again:
A is accumulator
PC is program counter
Oper is the following operand
MEM is the memory location specified by the following operand
m means the operation works from or on memory
i implies immediate mode
0 NOT (NOT A -> A)
1 SUBm (A - MEM -> A)
2 ADDm (A + MEM -> A)
3 ORm (A OR MEM -> A)
4 STOREm (A -> MEM)
5 BRANCHZERO ( IF flag zero set then OP->PC )
6 ANDm (A AND MEM -> A)
7 LOADm (MEM -> A)
8 Reserved for future use
9 SUBi ( A - Oper -> A)
10 ADDi ( A + Oper -> A)
11 ORi ( A OR Oper-> A)
12 IOWRITE (A to special IO for screen)
13 BRANCHALWAYS ( Oper -> PC )
14 ANDi ( A AND Oper -> A)
15 LOADi (Oper -> A)
Also if the add the destination and source after each opcode like this
source,dest
using the i and m prefix.
example:
ADDi i07,A
ANDm m01,A
STOREm A,m01
So your original programs
Example:
LOADm m05,A
07 05
Will load whatever is in memory location 05.
Example:
BRANCHALWAYS m10
13 10
Will move the program to memory location 10, and continue from there.
This program seems to contain errors.
Here's a sample program that calculates 1+2+3+... indefinitely, outputting after each addition.
Start m00
LOADi i00,A
ADDi i01,A
STOREm A,m01
ADDi i00,A
STOREm A,m07
IOWRITE
BRANCHALWAYS m00 "Start"
15 00
10 01
04 01
10 00
04 07
12 00
13 00
How many instructions can your computer store for one program? Does the program itself have to share memory locations with whatever it needs to store?
Shared memory, so that program should work. There's currently 8 bytes of memory, soon to be 16. 2 bytes per instruction, so up to 8 instructions once I've finished adding this memory.
count to ten and store it in memory 00
memory 01 is temp counter
m00 data 00 # <-- this is my way of saying manually put these values in the memory
m01 data 10 # countdown
start m02
loop
LOADm m00,A
ADDi i01,A
STOREm A,m00 # increment m00
LOADm m01,A
SUBi i01,A
STOREm A,m01 # decrement m01 countdown
BRANCHZERO exit # if countdown is 0 exit
BRANCHALWAYS loop
8 instructions
16 bytes
+2 for variables
2bytes too much, need a 24 byte memory :sad.gif:
After thinking about how to optomise this code for size, I came up with the following solution
First I realised that you could instead of counting from 10 down to 0, count from 246 to up to 0, that saves one branch. When I thought about both values incrementing I thought would it be possible to store them both in the same register? Then it dawned on me, yes it could. So the following is my modified program
count to ten and store it in memory 00
m00 data 00 # <-- this is my way of saying manually put these values in the memory
start m01
loop
LOADm m00,A
ADDi i01,A
STOREm A,m00 # increment m00
NOT A
ANDi i10,A
BRANCHZERO exit
BRANCHALWAYS loop
If you made a more powerful computer (don't take this as an insult your's is amazing work) say, 64 bits? Would it be theoretically possible to play minecraft on it? You would need a display and a method of control but would it be possible?
If you could somehow generate infinite time and a RL computer to end all computers, and you never got bored? Sure.
Usually I just browse the forums instead of posting.
but with this post i couldn't resist.
what kind of inputs/outputs are available?
I browsed the original post and they weren't listed.
perhaps a numpad and a few seven segs would be good for now.
I'm doubling the memory of my CPU to 16 bytes, and I want to make some more videos to show what it can do. I have one program to run on it in a video, and I'm looking for another one. Does anyone want to write a program to go in the video? I'll post some instructions below, and if I get any responses I might use one. By the way, this post is likely to change as the CPU changes and people tell me what I've done wrong. :biggrin.gif:
EDIT: There are no inputs at the moment, apart from loading code in, and the output is just a row of 8 redstone torches to show a single byte of output, so programs have to just run through themselves for now without further input. :smile.gif:
This is how it works:
The CPU starts at memory location 0. When it runs, it reads the op code at its current location, then it does that operation on whatever the next byte is. Here are the op codes:
The operations on constants use whatever the next byte is to do the operation. The operations on memory use the next byte as the memory address of the value to use.
Branching moves the program to the memory location that follows.
Here's a sample program that calculates 1+2+3+... indefinitely, outputting after each addition.
Which does:
Post here if you have a program, or if my instructions aren't very good and you don't understand. :tongue.gif:
Here's the most recent save file:http://lazcraft.tumblr.com/post/1602015698/cpu-save
Program for coding written by BopMeExtreme:
And another by aadnk, with instructions here.
This one is in-browser, by GICodeWarrior, instructions here.
*Head Implodes*
Need to write that table better.
I assume your CPU has only one register (the accumulator or A)
Addressing modes are then
Instruction mem
Instruction immediate
A is accumulator
PC is program counter
OP is the following operand
MEM is the memory location specified by the following operand
0 NOT (NOT A->A)
1 SUBMEM (A-MEM->A)
2 ADDMEM (A+MEM->A)
3 ORMEM (A OR MEM->A)
4 WRITE (A->MEM)
5 BRANCHZERO (IF flag zero set then OP->PC)
6 ANDMEM (A AND MEM->A)
7 LOAD (MEM->A)
8 NOT (How is this different to 0?)
9 SUBIMM ( A-OP->A)
10 ADDIMM ( A-OP
11 ORIMM ( A OR OP -> A)
12 WRITE out (Don't understand this opcode)
13 BRANCHALWAYS ( OP->PC )
14 ANDIMM ( A AND OP -> A)
15 LOAD constant (how can you load a constant? or are you using another register called constant)
Please correct me where I have got you CPU wrong.
Thanks, that looks much better. 0 NOT and 8 NOT do the same thing, one of them is a spare instruction, I haven't found anything to do with it yet. 12 writes to a register that I'm going to use as an output to a screen. At the moment it doesn't use OP, but I plan on using that as well eventually. 15 does OP->A.
Haha, I think it'd explode if I even considered trying that. :tongue.gif:
That's the plan, once the screen is working.
OK trying to simplify it again:
A is accumulator
PC is program counter
Oper is the following operand
MEM is the memory location specified by the following operand
m means the operation works from or on memory
i implies immediate mode
0 NOT (NOT A -> A)
1 SUBm (A - MEM -> A)
2 ADDm (A + MEM -> A)
3 ORm (A OR MEM -> A)
4 STOREm (A -> MEM)
5 BRANCHZERO ( IF flag zero set then OP->PC )
6 ANDm (A AND MEM -> A)
7 LOADm (MEM -> A)
8 Reserved for future use
9 SUBi ( A - Oper -> A)
10 ADDi ( A + Oper -> A)
11 ORi ( A OR Oper-> A)
12 IOWRITE (A to special IO for screen)
13 BRANCHALWAYS ( Oper -> PC )
14 ANDi ( A AND Oper -> A)
15 LOADi (Oper -> A)
Also if the add the destination and source after each opcode like this
source,dest
using the i and m prefix.
example:
ADDi i07,A
ANDm m01,A
STOREm A,m01
So your original programs
This program seems to contain errors.
I think it could be simpler than this.
Shared memory, so that program should work. There's currently 8 bytes of memory, soon to be 16. 2 bytes per instruction, so up to 8 instructions once I've finished adding this memory.
memory 01 is temp counter
8 instructions
16 bytes
+2 for variables
2bytes too much, need a 24 byte memory :sad.gif:
You do realize he is talking about a computer he made in game?
“Wha-what magazine?” “Tuba.”
I have changed the OP (adding "in minecraft") so that people don't get confused. :tongue.gif:
First I realised that you could instead of counting from 10 down to 0, count from 246 to up to 0, that saves one branch. When I thought about both values incrementing I thought would it be possible to store them both in the same register? Then it dawned on me, yes it could. So the following is my modified program
count to ten and store it in memory 00
7 instructions
14 bytes
+1 for variables
15bytes
Of course not, silly! His Processor isnt fast enough.
http://www.youtube.com/user/Caeviens?fe ... 96B9817BC6
If you could somehow generate infinite time and a RL computer to end all computers, and you never got bored? Sure.
Planning to do that when it's finished. I'm still adding stuff, like memory, a screen, etc.
Yay! :smile.gif:
http://www.youtube.com/user/theinternetftw
but with this post i couldn't resist.
what kind of inputs/outputs are available?
I browsed the original post and they weren't listed.
perhaps a numpad and a few seven segs would be good for now.
This thread is now [Diamond]