Skip to content

Instantly share code, notes, and snippets.

@thata
thata / cpu_test.rb
Created December 11, 2021 14:58
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
# bin2float.rb
# usage:
# ruby bin2float.rb 11000010111011010100000000000000 #=> -118.625
puts [ARGV[0]].pack('B*').unpack('g')
@thata
thata / top.sv
Created February 24, 2020 23:38
// uart 送信テスト
module top(
input clk,
input wire RsRx,
output wire RsTx,
output led
);
logic s_axi_aresetn = 1'b1;
logic interrupt;
@thata
thata / goodbye.s
Created March 27, 2019 15:20
MIPSの引数4つ以上の関数呼出し規約どうなってる?
goodbye:
.set nomips16
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
sw $fp,4($sp)
@thata
thata / min-caml_sparc_ppc.diff
Created March 21, 2019 11:07
MinCamlのSparcとPowerPCのdiff
diff -u SPARC/asm.ml PowerPC/asm.ml
--- SPARC/asm.ml 2019-03-19 21:12:59.000000000 +0900
+++ PowerPC/asm.ml 2019-03-19 21:12:59.000000000 +0900
@@ -1,4 +1,4 @@
-(* SPARC assembly with a few virtual instructions *)
+(* PowerPC assembly with a few virtual instructions *)
type id_or_imm = V of Id.t | C of int
type t = (* 命令の列 (caml2html: sparcasm_t) *)
@@ -6,23 +6,24 @@
@thata
thata / readmemh_sample.v
Last active January 23, 2019 01:02
$readmemh でメモリへデータをロードする Verilog のサンプル。このへん ( https://timetoexplore.net/blog/initialize-memory-in-verilog ) を参考にした。
`define ENABLE_ADC_CLOCK
`define ENABLE_CLOCK1
`define ENABLE_CLOCK2
`define ENABLE_SDRAM
`define ENABLE_HEX0
`define ENABLE_HEX1
`define ENABLE_HEX2
`define ENABLE_HEX3
`define ENABLE_HEX4
`define ENABLE_HEX5
@thata
thata / DE10_LITE_Golden_Top.v
Created January 23, 2019 00:59
$readmemh でメモリへデータをロードするサンプル。
`define ENABLE_ADC_CLOCK
`define ENABLE_CLOCK1
`define ENABLE_CLOCK2
`define ENABLE_SDRAM
`define ENABLE_HEX0
`define ENABLE_HEX1
`define ENABLE_HEX2
`define ENABLE_HEX3
`define ENABLE_HEX4
`define ENABLE_HEX5
@thata
thata / matrix.ino
Created August 7, 2018 20:48
TFT液晶でライフゲーム。
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Adafruit_TFTLCD.h>
#include <pin_magic.h>
#include <registers.h>
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
@thata
thata / index.html
Last active November 16, 2017 13:58
「1桁の月日の場合、十の位はゼロ埋めではなくスペースで埋めて、2桁の月の表記と縦のラインがそろうようにします」=> モノスペースじゃないフォントだとずれるのでは?というのを確認
<html>
<body>
<pre style="font-family: serif">
2017/ 1/ 1
2017/ 1/ 2
2017/ 1/ 3
2017/ 1/10
2017/ 1/28
2017/ 1/29
2017/ 1/30
@thata
thata / lifegame.ts
Created September 11, 2017 04:52
micro:bitでライフゲーム。
let cells = [
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, false, false],
[false, false, false, false, false],
]
function next_generation() {
let newCells = [