summaryrefslogtreecommitdiff
path: root/c/squares
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2026-05-23 20:14:34 -0500
committercheapie <no-email-for-you@example.com>2026-05-23 20:14:34 -0500
commit85b5fde272be6ab543aa866baebabddc24566bdb (patch)
treeb4f2e3bb634effe51c2bdc5585ca4ea8b98d6dfa /c/squares
downloadrvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar
rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.gz
rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.bz2
rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.xz
rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.zip
Add initial content
Diffstat (limited to 'c/squares')
-rw-r--r--c/squares/Makefile20
-rw-r--r--c/squares/rvcontroller.ld45
-rw-r--r--c/squares/squares.b8
-rw-r--r--c/squares/squares.c169
-rwxr-xr-xc/squares/squares.elfbin0 -> 6752 bytes
-rw-r--r--c/squares/squares.hex42
-rw-r--r--c/squares/squares.obin0 -> 2336 bytes
7 files changed, 284 insertions, 0 deletions
diff --git a/c/squares/Makefile b/c/squares/Makefile
new file mode 100644
index 0000000..f957bfa
--- /dev/null
+++ b/c/squares/Makefile
@@ -0,0 +1,20 @@
+all: squares.hex
+
+squares.o: squares.c
+ clang -target riscv32-none-elf -I../rvcontroller-libraries -march=rv32imacb_zicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt -ffreestanding -O3 -c -o squares.o squares.c
+
+squares.elf: ../rvcontroller-libraries/rvcontroller-init.o ../rvcontroller-libraries/rvcontroller-ecalls.o squares.o
+ riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o squares.elf ../rvcontroller-libraries/rvcontroller-init.o squares.o ../rvcontroller-libraries/rvcontroller-ecalls.o
+
+dump: squares.elf
+ riscv32-none-elf-objdump -d squares.elf
+
+squares.hex: squares.elf
+ riscv32-none-elf-objcopy -O ihex squares.elf squares.hex
+
+load: squares.hex
+ bash -c "wl-copy < squares.hex"
+
+clean:
+ rm -f squares.bin squares.elf squares.o init.o
+
diff --git a/c/squares/rvcontroller.ld b/c/squares/rvcontroller.ld
new file mode 100644
index 0000000..985892b
--- /dev/null
+++ b/c/squares/rvcontroller.ld
@@ -0,0 +1,45 @@
+/* Thanks https://github.com/darklife/darkriscv */
+ __heap_size = 0x200; /* required amount of heap */
+ __stack_size = 0x800; /* required amount of stack */
+ ENTRY(_start);
+ MEMORY
+ {
+ RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x10000
+ }
+ SECTIONS
+ {
+ .text :
+ {
+ *(.text.startup)
+ *(.text)
+ *(.text)
+ *(.rodata*)
+ } > RAM
+ .data :
+ {
+ *(.sbss)
+ *(.data)
+ *(.bss)
+ *(.rela*)
+ *(COMMON)
+ } > RAM
+
+ .heap :
+ {
+ . = ALIGN(4);
+ PROVIDE ( end = . );
+ _sheap = .;
+ . = . + __heap_size;
+ . = ALIGN(4);
+ _eheap = .;
+ } >RAM
+
+ .stack :
+ {
+ . = ALIGN(4);
+ _estack = .;
+ . = . + __stack_size;
+ . = ALIGN(4);
+ _sstack = .;
+ } >RAM
+ }
diff --git a/c/squares/squares.b b/c/squares/squares.b
new file mode 100644
index 0000000..b235485
--- /dev/null
+++ b/c/squares/squares.b
@@ -0,0 +1,8 @@
+++++[>+++++<-]>[<+++++>-]+<+[
+ >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
+ >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
+ <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-
+]
+[Outputs square numbers from 0 to 10000.
+Daniel B Cristofani (cristofdathevanetdotcom)
+http://www.hevanet.com/cristofd/brainfuck/]
diff --git a/c/squares/squares.c b/c/squares/squares.c
new file mode 100644
index 0000000..435ddff
--- /dev/null
+++ b/c/squares/squares.c
@@ -0,0 +1,169 @@
+/* This is a translation of squares.b, generated by bftoc.py (by Paul Kaefer)
+ * It was generated on Friday, May 15, 2026 at 07:20PM
+ */
+
+#include "rvcontroller-ecalls.h"
+
+void main(void)
+{
+ int size = 1000;
+ int tape[size];
+ int i = 0;
+
+ /* Clearing the tape (array) */
+ for (i=0; i<size; i++)
+ tape[i] = 0;
+
+ int ptr = 0;
+
+ tape[ptr] += 4;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ tape[ptr] += 5;
+ ptr -= 1;
+ tape[ptr] -= 1;
+ }
+ ptr += 1;
+ while (tape[ptr] != 0)
+ {
+ ptr -= 1;
+ tape[ptr] += 5;
+ ptr += 1;
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 1;
+ ptr -= 1;
+ tape[ptr] += 1;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ tape[ptr] += 1;
+ ptr += 1;
+ tape[ptr] += 1;
+ ptr -= 2;
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 2;
+ ptr += 2;
+ while (tape[ptr] != 0)
+ {
+ ptr -= 2;
+ tape[ptr] += 1;
+ ptr += 2;
+ tape[ptr] -= 1;
+ }
+ ptr += 3;
+ while (tape[ptr] != 0)
+ {
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 2;
+ ptr += 1;
+ while (tape[ptr] != 0)
+ {
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 1;
+ ptr += 3;
+ tape[ptr] += 1;
+ while (tape[ptr] != 0)
+ {
+ while (tape[ptr] != 0)
+ {
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 6;
+ ptr += 3;
+ }
+ ptr -= 3;
+ while (tape[ptr] != 0)
+ {
+ while (tape[ptr] != 0)
+ {
+ ptr -= 1;
+ tape[ptr] += 8;
+ ptr -= 1;
+ tape[ptr] += 2;
+ ptr += 2;
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 1;
+ ptr -= 1;
+ printchar(tape[ptr]);
+ ptr -= 1;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ tape[ptr] -= 4;
+ ptr -= 1;
+ tape[ptr] -= 1;
+ }
+ ptr -= 1;
+ }
+ ptr -= 2;
+ while (tape[ptr] != 0)
+ {
+ ptr += 5;
+ while (tape[ptr] != 0)
+ {
+ ptr += 3;
+ while (tape[ptr] != 0)
+ {
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 9;
+ ptr -= 1;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ tape[ptr] -= 1;
+ ptr -= 1;
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 9;
+ ptr += 1;
+ while (tape[ptr] != 0)
+ {
+ tape[ptr] -= 1;
+ while (tape[ptr] != 0)
+ {
+ ptr -= 1;
+ tape[ptr] -= 1;
+ ptr += 1;
+ tape[ptr] -= 1;
+ }
+ tape[ptr] += 1;
+ while (tape[ptr] != 0)
+ {
+ ptr -= 3;
+ }
+ }
+ ptr -= 1;
+ while (tape[ptr] != 0)
+ {
+ ptr += 1;
+ tape[ptr] += 1;
+ ptr -= 1;
+ tape[ptr] -= 1;
+ }
+ ptr += 1;
+ }
+ ptr -= 2;
+ tape[ptr] -= 1;
+ }
+ ptr -= 2;
+ tape[ptr] -= 1;
+ }
+ while (tape[ptr] != 0)
+ {
+ printchar(tape[ptr]);
+ printchar(tape[ptr]);
+ printchar(tape[ptr]);
+ }
+
+}
+
diff --git a/c/squares/squares.elf b/c/squares/squares.elf
new file mode 100755
index 0000000..e0050b8
--- /dev/null
+++ b/c/squares/squares.elf
Binary files differ
diff --git a/c/squares/squares.hex b/c/squares/squares.hex
new file mode 100644
index 0000000..0df4797
--- /dev/null
+++ b/c/squares/squares.hex
@@ -0,0 +1,42 @@
+:10000000370101002920A9487300000082804EB802
+:10001000130101801301018605650A95233485FCCF
+:1000200005650A95233025FD05650A95233C45FBAA
+:1000300005650A95233865FB08089305F57F9385C8
+:10004000157A232005001105E31DB5FE4245D24572
+:10005000130645003345A5202E955105B3F5C50E71
+:100060003355C50E4D8D0DCD3345A5208545050570
+:100070002AC82ECA0DE905650A95033485FC056575
+:100080000A95033905FC05650A95033A85FB056564
+:100090000A95033B05FB1301017F1301017B4EBE53
+:1000A00005452AC82ACA8144930B0101930981029C
+:1000B0000949054A254B994A080809A89304E5FF10
+:1000C00033C574210C41FD150CC1D5D54C4199C9DE
+:1000D000104554452E96B69510C54CC523222501D2
+:1000E00091E519A84C452322250199C50946FD151E
+:1000F0000506F5FD50C14CC5232C2501232E4501D5
+:10010000A90433C574210C4185050CC199C54C4522
+:100110002320550131058D04FDF91385D4FF3344A7
+:100120007521084009ED1385B4FFB34575218C4155
+:10013000B9E969B7032544FF5114F5146DD583253A
+:10014000C4FF032684FFB365B5203325C520232CC7
+:10015000A4FE232EB4FE2320440113F5F50F7520D1
+:10016000032584FF61D98325C4FF0A05898D232CCB
+:1001700004FE232EB4FE7DBF7915B3457521904151
+:100180007D1690C105DE1505B345752190416DD6EC
+:10019000904523A6650109CADD567D16850675FEC4
+:1001A000B306D04090C5D4C523A46501130635001D
+:1001B000B34576219441638B460199E232851DA0B7
+:1001C00003A6C5FF158E050623AEC5FE23A0450177
+:1001D00013066500B3453521328503A645FFD115C9
+:1001E000751565FE03A6C5FF41DA23AE05FE90C175
+:1001F000B3457521904149FE41B785487300000021
+:1002000082809148730000008280AD487300000036
+:1002100082809308100873000000828093085008C1
+:1002200073000000828093087008730000008280D1
+:10023000732510C08280732500C0828093086008F7
+:100240007300000082800589F322008093920248A7
+:10025000B3E2A20073900280828095487300000090
+:10026000828093080008730000008280A148730018
+:100270000000828093083008730000008280930899
+:080280004008730000008280B9
+:00000001FF
diff --git a/c/squares/squares.o b/c/squares/squares.o
new file mode 100644
index 0000000..64e0c71
--- /dev/null
+++ b/c/squares/squares.o
Binary files differ