This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 にする) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4649 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 例の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(//)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RISC-V subset simulator | |
# usage: | |
# ruby rv32sim.rb sample/fibonacci.rom | |
class Memory | |
WORD_SIZE = 4 | |
attr_accessor :data | |
def initialize(data = "\0" * 512) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./rv32sim" | |
def _add(rd, rs1, rs2) | |
0b0110011 | | |
(rd << 7) | | |
(0x0 << 12) | | |
(rs1 << 15) | | |
(rs2 << 20) | | |
(0x00 << 25) | |
end |
NewerOlder