From 4920c3b92b27ac262e21a28471f72b30d56187c2 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Tue, 15 Jul 2025 12:09:11 -0400 Subject: [PATCH] clean up and added code for a simple counting function as a sanity check in the sandbox. --- definitions.asm | 78 --------------- src/{ => TC_answers}/add.asm | 0 src/{ => TC_answers}/laser_canons.asm | 0 src/{ => TC_answers}/masking_time.asm | 0 src/{ => TC_answers}/memory_test.asm | 0 src/{ => TC_answers}/special_invasion.asm | 0 src/{ => TC_answers}/storage_cracker.asm | 0 src/{ => TC_answers}/the_maze.asm | 0 src/definitions.asm | 116 ++++++++++++++++++++++ src/misc/50count.asm | 30 ++++++ scratch.asm => src/scratch.asm | 0 11 files changed, 146 insertions(+), 78 deletions(-) delete mode 100644 definitions.asm rename src/{ => TC_answers}/add.asm (100%) rename src/{ => TC_answers}/laser_canons.asm (100%) rename src/{ => TC_answers}/masking_time.asm (100%) rename src/{ => TC_answers}/memory_test.asm (100%) rename src/{ => TC_answers}/special_invasion.asm (100%) rename src/{ => TC_answers}/storage_cracker.asm (100%) rename src/{ => TC_answers}/the_maze.asm (100%) create mode 100644 src/definitions.asm create mode 100644 src/misc/50count.asm rename scratch.asm => src/scratch.asm (100%) diff --git a/definitions.asm b/definitions.asm deleted file mode 100644 index 9581ef5..0000000 --- a/definitions.asm +++ /dev/null @@ -1,78 +0,0 @@ -; see https://github.com/hlorenzi/customasm for documentation - -#bankdef program -{ - #bits 8 - #addr 0x00 - #size 0xFF - #outp 0x00 -} -#subruledef register -{ - 0 => 0b000 - 1 => 0b001 - 2 => 0b010 - 3 => 0b011 - 4 => 0b100 - 5 => 0b101 - -} - -#ruledef -{ - imm6 {value} => 0b00 @ value`6 - load r{src: register}, r{dst: register} => 0b10 @ src`3 @ dst`3 - aload => 0b10 @ 0b110 @ 0b110 - in r{r: register} => 0b10 @ 0b110 @ r - out r{r: register} => 0b10 @ r @ 0b110 -} - -#ruledef -{ - or => 0b01 @ 0b000 @ 0b000 - nand => 0b01 @ 0b000 @ 0b001 - nor => 0b01 @ 0b000 @ 0b010 - and => 0b01 @ 0b000 @ 0b011 - xnor => 0b01 @ 0b000 @ 0b100 - xor => 0b01 @ 0b000 @ 0b101 - not => 0b01 @ 0b000 @ 0b110 - ALU_EXT0_RES7 => 0b01 @ 0b000 @ 0b111 - ashr => 0b01 @ 0b001 @ 0b000 - div => 0b01 @ 0b001 @ 0b001 - mul => 0b01 @ 0b001 @ 0b010 - sub => 0b01 @ 0b001 @ 0b011 - add => 0b01 @ 0b001 @ 0b100 - ALU_EXT1_RES5 => 0b01 @ 0b001 @ 0b101 - ALU_EXT1_RES6 => 0b01 @ 0b001 @ 0b110 - ALU_EXT1_RES7 => 0b01 @ 0b001 @ 0b111 - rol => 0b01 @ 0b010 @ 0b000 - ror => 0b01 @ 0b010 @ 0b001 - shr => 0b10 @ 0b010 @ 0b010 - shl => 0b10 @ 0b010 @ 0b011 - neg => 0b10 @ 0b010 @ 0b100 - ALU_EXT2_RES5 => 0b10 @ 0b010 @ 0b101 - ALU_EXT2_RES6 => 0b10 @ 0b010 @ 0b110 - ALU_EXT2_RES7 => 0b10 @ 0b010 @ 0b111 - ; and so on... - ALU_EXT7_RES1 => 0b01 @ 0b111 @ 0b000 -} - -; conditional jump block -#ruledef -{ - bn => 0b11 @ 0b000 @ 0b000 - beqz => 0b11 @ 0b000 @ 0b001 - bltz => 0b11 @ 0b000 @ 0b010 - blez => 0b11 @ 0b000 @ 0b011 - ba => 0b11 @ 0b000 @ 0b100 - bnez => 0b11 @ 0b000 @ 0b101 - bgez => 0b11 @ 0b000 @ 0b110 - bgtz => 0b11 @ 0b000 @ 0b111 -} - -; halt encodings -#ruledef -{ - hcf => 0b10 @ 0b111 @ 0b111 - halt => 0b10 @ 0b111 @ 0b111 -} diff --git a/src/add.asm b/src/TC_answers/add.asm similarity index 100% rename from src/add.asm rename to src/TC_answers/add.asm diff --git a/src/laser_canons.asm b/src/TC_answers/laser_canons.asm similarity index 100% rename from src/laser_canons.asm rename to src/TC_answers/laser_canons.asm diff --git a/src/masking_time.asm b/src/TC_answers/masking_time.asm similarity index 100% rename from src/masking_time.asm rename to src/TC_answers/masking_time.asm diff --git a/src/memory_test.asm b/src/TC_answers/memory_test.asm similarity index 100% rename from src/memory_test.asm rename to src/TC_answers/memory_test.asm diff --git a/src/special_invasion.asm b/src/TC_answers/special_invasion.asm similarity index 100% rename from src/special_invasion.asm rename to src/TC_answers/special_invasion.asm diff --git a/src/storage_cracker.asm b/src/TC_answers/storage_cracker.asm similarity index 100% rename from src/storage_cracker.asm rename to src/TC_answers/storage_cracker.asm diff --git a/src/the_maze.asm b/src/TC_answers/the_maze.asm similarity index 100% rename from src/the_maze.asm rename to src/TC_answers/the_maze.asm diff --git a/src/definitions.asm b/src/definitions.asm new file mode 100644 index 0000000..bee9668 --- /dev/null +++ b/src/definitions.asm @@ -0,0 +1,116 @@ +; see https://github.com/hlorenzi/customasm for documentation regarding customasm + +; ECP8 is a 8-bit Turring complete CPU for the game 'Turring Complete' +; - Instructions are fixed width 8-bit instructions +; - Can directly load into r0 up to a 6-bit constant +; - ALU with integer add/sub/mul & arithmetic/logical shift operations (div disabled) +; +; +; # Registers +; - r0 is a scratch register +; - r1,2 are used as the input to the ALU (A & B) +; - r3,r4 are used as the output from the ALU (C & sometimes D) +; - r5 is also a scratch register in practice +; +; # Instruction space layout +; - encodings begining with 0b00 are immediate value loads +; - encodings with 0b01 are ALU operations and are encoded as 0b01:EXT:FUNCTION +; - encodings begining with 0b10 are register and bus i/o functions +; - encodings beinging with 0b11 are for conditional checks versus the contents of the r3 register +; the r0 register holds the location of the location. +; +; As a consequence jumping to an immediate requires 2 clock's (1 for the imm6 and then the branch check) + +#bankdef program +{ + #bits 8 + #addr 0x00 + #size 0xFF + #outp 0x00 +} + +#subruledef register +{ + 0 => 0b000 + 1 => 0b001 + 2 => 0b010 + 3 => 0b011 + 4 => 0b100 + 5 => 0b101 + +} + +; immediate load encodings +#ruledef +{ + imm6 {value} => 0b00 @ value`6 +} + +; register and bus i/o encodings +#ruledef +{ + load r{src: register}, r{dst: register} => 0b10 @ src`3 @ dst`3 + aload => 0b10 @ 0b110 @ 0b110 + in r{r: register} => 0b10 @ 0b110 @ r + out r{r: register} => 0b10 @ r @ 0b110 +} + +; EXT0 functions +#ruledef +{ + or => 0b01 @ 0b000 @ 0b000 + nand => 0b01 @ 0b000 @ 0b001 + nor => 0b01 @ 0b000 @ 0b010 + and => 0b01 @ 0b000 @ 0b011 + xnor => 0b01 @ 0b000 @ 0b100 + xor => 0b01 @ 0b000 @ 0b101 + not => 0b01 @ 0b000 @ 0b110 + ;ALU_EXT0_RES7 => 0b01 @ 0b000 @ 0b111 +} + +; EXT1 functions +#ruledef +{ + ashr => 0b01 @ 0b001 @ 0b000 + div => 0b01 @ 0b001 @ 0b001 + mul => 0b01 @ 0b001 @ 0b010 + sub => 0b01 @ 0b001 @ 0b011 + add => 0b01 @ 0b001 @ 0b100 + ;ALU_EXT1_RES5 => 0b01 @ 0b001 @ 0b101 + ;ALU_EXT1_RES6 => 0b01 @ 0b001 @ 0b110 + ;ALU_EXT1_RES7 => 0b01 @ 0b001 @ 0b111 +} + +; EXT2 functions +#ruledef +{ + rol => 0b01 @ 0b010 @ 0b000 + ror => 0b01 @ 0b010 @ 0b001 + shr => 0b01 @ 0b010 @ 0b010 + shl => 0b01 @ 0b010 @ 0b011 + neg => 0b01 @ 0b010 @ 0b100 + ;ALU_EXT2_RES5 => 0b01 @ 0b010 @ 0b101 + ;ALU_EXT2_RES6 => 0b01 @ 0b010 @ 0b110 + ;ALU_EXT2_RES7 => 0b01 @ 0b010 @ 0b111 +} + +; and so on...currently everything above EXT2 is unimplemented and left floating, and should just be no-op (untested) + +; conditional block encodings +#ruledef +{ + bn => 0b11 @ 0b000 @ 0b000 + beqz => 0b11 @ 0b000 @ 0b001 + bltz => 0b11 @ 0b000 @ 0b010 + blez => 0b11 @ 0b000 @ 0b011 + ba => 0b11 @ 0b000 @ 0b100 + bnez => 0b11 @ 0b000 @ 0b101 + bgez => 0b11 @ 0b000 @ 0b110 + bgtz => 0b11 @ 0b000 @ 0b111 +} + +; halt encoding(s) +#ruledef +{ + halt => 0b10 @ 0b111 @ 0b111 +} diff --git a/src/misc/50count.asm b/src/misc/50count.asm new file mode 100644 index 0000000..7cdefac --- /dev/null +++ b/src/misc/50count.asm @@ -0,0 +1,30 @@ +#include "../definitions.asm" +#bank program + +prog: + imm6 0x0 + load r0, r1 ; init r1 to 0 + +.loop: + imm6 0x1 + load r0, r2 ; value to increment by + + ; r1+r2=(r3 & r4) + add ; add r1 + value + load r3, r4 ; over-write upper MSB to store a copy + load r3, r2 ; store result in r2 + + imm6 0x32 + load r0, r1 + sub ; 50 - r2 = remainder + + imm6 prog.result + beqz ; if r3 == 0 branch to [r0] + + load r4, r1 + imm6 prog.loop + ba ; else, copy result to r1 and loop + +.result: + out r4 + halt \ No newline at end of file diff --git a/scratch.asm b/src/scratch.asm similarity index 100% rename from scratch.asm rename to src/scratch.asm