Skip to content

Instantly share code, notes, and snippets.

@thata
thata / ssd1331_on_off.ino
Created September 11, 2023 14:56
Arduino の digitalWrite だけで有機ELディスプレイ SSD1331 の電源をオン→オフ
#define sclk 9
#define mosi 10
#define rst 11
#define dc 12
#define cs 13
void initSPI() {
// Init basic control pins common to all connection types
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH); // deselect(データ送信の時だけ select = LOW にする)
@thata
thata / 4649.rb
Last active August 2, 2023 13:43
MinRuby Compiler
4649
@thata
thata / main.rb
Last active August 17, 2022 15:06
件のJavaのコード
# 例のJavaのコードをRubyへ移植
#
# usage: echo "3\nfoo foo\nbar ber\nbuzz buzzz" | ruby main.rb
# #=> 3
# 渡された二つの文字列の差異の数を返す
def num_of_difference(word1, word2)
return word1.size if word1.size != word2.size
pairs = word1.split(//).zip(word2.split(//))
@thata
thata / min-caml_ppc_x86.diff
Created June 16, 2022 13:19
diff min-caml-ppc min-caml-x86
Common subdirectories: min-caml-ppc/.git and min-caml-x86/.git
Common subdirectories: min-caml-ppc/PowerPC and min-caml-x86/PowerPC
Common subdirectories: min-caml-ppc/SPARC and min-caml-x86/SPARC
diff min-caml-ppc/asm.ml min-caml-x86/asm.ml
1c1
< (* PowerPC assembly with a few virtual instructions *)
---
> (* 2オペランドではなく3オペランドのx86アセンブリもどき *)
9,10c9
< | Li of int
@thata
thata / cpu_test.rb
Created June 13, 2022 20:42
jalr tests
def test_jalr
cpu = Cpu.new
# XXX: 行き当たりばったりに書いたのでゴチャゴチャしてる...
rom = [
_addi(2, 0, 40), # x2 = foo
_jalr(1, 2, 0), # call foo ( t=pc+4; pc=(x2+0) & ~1; x1=t )
_add(31, 29, 30), # x31 = x29 + x30
_nop,
_jalr(1, 31, -5), # call bar ( t=pc+4; pc=(x31-5)&~1); x1=t )
@thata
thata / rv32sim.rb
Created June 10, 2022 11:51
rv32sim: Small RISC-V Subset Simulator
# RISC-V subset simulator
# usage:
# ruby rv32sim.rb sample/fibonacci.rom
class Memory
WORD_SIZE = 4
attr_accessor :data
def initialize(data = "\0" * 512)
@thata
thata / hello.S
Created June 3, 2022 15:05
RISC-VでHELLO WORLD
# hello
#
# $ riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wl,-Ttext=0x00 -nostdlib -o hello.elf hello.S
# $ riscv64-unknown-elf-objcopy -O binary hello.elf hello.rom
# $ ruby rv32sim.rb hello.rom
.text
.globl _start
.type _start, @function
_start:
@thata
thata / fibonacci.S
Last active June 3, 2022 08:51
rv32sim - One file RISC-V simulator
# fibonacci for RV32
#
# $ riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wl,-Ttext=0x00 -nostdlib -o fibonacci fibonacci.S
# $ riscv64-unknown-elf-objcopy -O binary fibonacci fibonacci.rom
# $ ruby rv32sim.rb fibonacci.rom
.text
.globl _start
.type _start, @function
_start:
@thata
thata / fibonacci.s
Created December 12, 2021 06:33
RISC-Vでフィボナッチ数を計算
# fibonacci for RV32
#
# $ riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wl,-Ttext=0x00 -nostdlib -o fibonacci fibonacci.s
# $ riscv64-unknown-elf-objcopy -O binary fibonacci fibonacci.rom
# $ ruby rv32sim.rb fibonacci.rom
.text
.globl _start
.type _start, @function
_start:
@thata
thata / cpu_test.rb
Last active December 11, 2021 15:02
rv32sim: RISC-V(RV32) subset simulator
require "./rv32sim"
def _add(rd, rs1, rs2)
0b0110011 |
(rd << 7) |
(0x0 << 12) |
(rs1 << 15) |
(rs2 << 20) |
(0x00 << 25)
end