From: j8takagi Date: Fri, 2 Nov 2012 11:06:09 +0000 (+0900) Subject: 割算方式とカウンタ方式でディレクトリを分割 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a301513888b0d0116ad78631855ed613028c5b2;p=fizzbuzz.git 割算方式とカウンタ方式でディレクトリを分割 --- diff --git a/cnt/c/Makefile b/cnt/c/Makefile new file mode 100644 index 0000000..f271073 --- /dev/null +++ b/cnt/c/Makefile @@ -0,0 +1,12 @@ +CC ?= gcc +CFLAGS ?= -g -Wall -Wextra + +.PHONY: all clean + +all: fizzbuzz + +fizzbuzz: fizzbuzz.c + $(CC) $(CFLAGS) -o $@ $^ + +clean: + @$(RMF) fizzbuzz diff --git a/c/fizzbuzz2.c b/cnt/c/fizzbuzz.c similarity index 100% rename from c/fizzbuzz2.c rename to cnt/c/fizzbuzz.c diff --git a/casl/.gitignore b/cnt/casl/.gitignore similarity index 100% rename from casl/.gitignore rename to cnt/casl/.gitignore diff --git a/casl/casl2lib/abs.casl b/cnt/casl/casl2lib/abs.casl similarity index 100% rename from casl/casl2lib/abs.casl rename to cnt/casl/casl2lib/abs.casl diff --git a/casl/casl2lib/divl.casl b/cnt/casl/casl2lib/divl.casl similarity index 100% rename from casl/casl2lib/divl.casl rename to cnt/casl/casl2lib/divl.casl diff --git a/casl/casl2lib/outl.casl b/cnt/casl/casl2lib/outl.casl similarity index 100% rename from casl/casl2lib/outl.casl rename to cnt/casl/casl2lib/outl.casl diff --git a/casl/casl2lib/rev.casl b/cnt/casl/casl2lib/rev.casl similarity index 100% rename from casl/casl2lib/rev.casl rename to cnt/casl/casl2lib/rev.casl diff --git a/casl/fizzbuzz2.casl b/cnt/casl/fizzbuzz.casl similarity index 100% rename from casl/fizzbuzz2.casl rename to cnt/casl/fizzbuzz.casl diff --git a/emacslisp/.gitignore b/cnt/emacslisp/.gitignore similarity index 100% rename from emacslisp/.gitignore rename to cnt/emacslisp/.gitignore diff --git a/ruby/fizzbuzz2.rb b/cnt/ruby/fizzbuzz.rb similarity index 100% rename from ruby/fizzbuzz2.rb rename to cnt/ruby/fizzbuzz.rb diff --git a/c/Makefile b/mod/c/Makefile similarity index 100% rename from c/Makefile rename to mod/c/Makefile diff --git a/c/fizzbuzz.c b/mod/c/fizzbuzz.c similarity index 100% rename from c/fizzbuzz.c rename to mod/c/fizzbuzz.c diff --git a/mod/casl/.gitignore b/mod/casl/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/mod/casl/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/mod/casl/casl2lib/abs.casl b/mod/casl/casl2lib/abs.casl new file mode 100644 index 0000000..be0b922 --- /dev/null +++ b/mod/casl/casl2lib/abs.casl @@ -0,0 +1,17 @@ +;;; GR1を符号付き整数とみなし、絶対値に変換 +;;; 入力 GR1:-32768から32767の整数 +;;; 出力 GR1:入力された整数の絶対値 +;;; OF:入力されたGR1が-32768の場合、1 +;;; SF:入力されたGR1が負数(-32767〜-1)の場合、1 +ABS START + AND GR1,GR1 + JPL FIN + JZE FIN + XOR GR1,ALLON + ADDA GR1,ONE + JOV FIN + CPL GR1,ALLON +FIN RET +ONE DC 1 +ALLON DC #FFFF + END diff --git a/mod/casl/casl2lib/divl.casl b/mod/casl/casl2lib/divl.casl new file mode 100644 index 0000000..3591366 --- /dev/null +++ b/mod/casl/casl2lib/divl.casl @@ -0,0 +1,47 @@ +;;; 0〜65535の範囲にある正数の割算(筆算方式)を行う +;;; 入力 GR1:被除数 GR2:除数 +;;; 出力 GR0:商 GR3:剰余 +;;; (GR2 = 0)の場合、GR0 GR3とも0になり、オーバーフロー +DIVL START + PUSH 0,GR1 + PUSH 0,GR2 + PUSH 0,GR4 + XOR GR0,GR0 ; GR0:商 初期化 + XOR GR3,GR3 ; GR3:剰余 初期化 + AND GR2,GR2 ; (GR2 = 0)の場合、DIVZEROへジャンプ + JZE DIVZERO ; ↓ + AND GR1,GR1 ; (GR1 = 0)の場合、FINへジャンプ + JZE FIN ; ↓ + ST GR2,Y ; YにGR2の初期値を保存 + LAD GR4,1 ; GR4:対象ビットのインデックス 初期化 +SL CPL GR2,GR1 ; ループ先頭。(GR2 > GR1)の場合、LOOPへループ脱出 + JPL LOOP ; ↓ + SLL GR4,1 ; GR4を1回左シフト + ST GR2,TMP ; GR2の値をTMPに退避 + SLL GR2,1 ; GR2を1回左シフト + JOV YOV ; オーバーフローの場合は、YOVへジャンプ + JUMP SL ; ループ終端 +YOV LD GR2,TMP ; GR2の値をTMPから復元 + SRL GR4,1 ; GR4を1回右シフト + JUMP LPIN ; LPINへジャンプ +LOOP SRL GR4,1 ; ループ先頭。GR4を1回右シフト + JZE SETMOD ; (GR4 = 0)の場合、SETMODへループ脱出 + SRL GR2,1 ; GR2を1回右シフト + CPL GR1,Y ; (GR1 < Y)の場合、SETMODへループ脱出 + JMI SETMOD ; ↓ + CPL GR1,GR2 ; (GR1 < GR2)の場合、ループ先頭へジャンプ + JMI LOOP ; ↓ +LPIN SUBL GR1,GR2 ; GR1 <- GR1 - GR2 + ADDL GR0,GR4 ; GR0 <- GR0 + GR4 + JUMP LOOP ; ループ終端 +DIVZERO LAD GR3,#8000 ; 強制的にオーバーフローを発生させ、GR3 <- 0 + SLL GR3,1 ; ↓ + JUMP FIN ; FIN へジャンプ +SETMOD LD GR3,GR1 ; GR3 <- GR1。剰余の設定 +FIN POP GR4 + POP GR2 + POP GR1 + RET +Y DS 1 +TMP DS 1 + END diff --git a/mod/casl/casl2lib/outl.casl b/mod/casl/casl2lib/outl.casl new file mode 100644 index 0000000..a2967d8 --- /dev/null +++ b/mod/casl/casl2lib/outl.casl @@ -0,0 +1,36 @@ +;;; GR1に格納された値を、10進数の整数値(0〜65535)として表示 +;;; 依存プログラム: DIVL, REV +OUTL START + RPUSH + LAD GR2,10 ; GR2に10進数の「10」を格納。 + LAD GR0,0 ; GR0 <- 0 + XOR GR4,GR4 ; 整数値の長さ + AND GR1,GR1 ; GR1をテスト + JZE ZERO ; GR1が0の場合、ZEROにジャンプ +STI CPL GR1,GR2 ; ループ先頭。(GR1 < GR2)の場合は、ループ脱出 + JMI STLST ; ↓ + CALL DIVL ; GR1とGR2の、商をGR0、剰余をGR3に格納 + LD GR1,GR3 ; GR1にGR3をコピー + LD GR1,NCHAR,GR1 ; GR1を文字に変換 + ST GR1,STR,GR4 ; (STR + GR4) <- GR1 + LAD GR4,1,GR4 ; GR4 <- GR4 + 1 + LD GR1,GR0 ; GR0をGR1にコピー + JUMP STI ; ループ終端 +STLST LD GR1,NCHAR,GR1 ; GR1を文字に変換 + ST GR1,STR,GR4 ; (STR + GR4) <- GR1 + LAD GR4,1,GR4 ; GR4 <- GR4 + 1 + JUMP PRT ; PRTにジャンプ +ZERO LD GR1,NCHAR ; 「0」をSTR領域に格納 + ST GR1,STR,GR4 ; ↓ (STR + GR4) <- GR1 + LAD GR4,1,GR4 ; ↓ GR4 <- GR4 + 1 +PRT ST GR4,LEN ; LEN <- GR4 + LD GR2,LEN ; GR2にLENの値を格納 + LAD GR1,STR ; GR1に文字列のアドレスを格納 + CALL REV ; 文字列を逆順に並べ替え + OUT STR,LEN ; 文字列を出力 + RPOP + RET +STR DS 17 ; 符号付き2進数で表記した場合を想定 +LEN DS 1 +NCHAR DC '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + END diff --git a/mod/casl/casl2lib/rev.casl b/mod/casl/casl2lib/rev.casl new file mode 100644 index 0000000..397c5c4 --- /dev/null +++ b/mod/casl/casl2lib/rev.casl @@ -0,0 +1,27 @@ +;;; メモリー上にある指定されたアドレス、長さの文字列を逆順に並べ替える +;;; 例: 12345 -> 54321、54321- -> -12345 +;;; 入力 GR1:文字列のアドレス GR2:文字列の長さ +;;; 出力 (同上) +REV START + RPUSH + LAD GR3,0 ; GR3の初期化 +PU CPL GR3,GR2 ; ループ先頭。(GR3 = GR2)の場合、ループ脱出 + JZE NEXT ; ↓ + LD GR4,GR1 ; GR4 <- GR1 + ADDL GR4,GR3 ; GR4 <- GR4 + GR3 + LD GR5,0,GR4 ; GR5 <- GR4アドレスの値 + PUSH 0,GR5 ; GR5をプッシュ + LAD GR3,1,GR3 ; GR3 <- GR3 + 1 + JUMP PU ; ループ終端 +NEXT LAD GR3,0 ; GR3の初期化 +PO CPL GR3,GR2 ; ループ先頭。(GR3 = GR2)の場合、ループ脱出 + JZE FIN ; ↓ + POP GR5 ; GR5にポップ + LD GR4,GR1 ; GR4にGR1の値をコピー + ADDL GR4,GR3 ; GR4 <- GR4 + GR3 + ST GR5,0,GR4 ; GR4のアドレス <- GR5の値 + LAD GR3,1,GR3 ; GR3 <- GR3 + 1 + JUMP PO ; ループ終端 +FIN RPOP + RET + END diff --git a/casl/fizzbuzz.casl b/mod/casl/fizzbuzz.casl similarity index 100% rename from casl/fizzbuzz.casl rename to mod/casl/fizzbuzz.casl diff --git a/mod/emacslisp/.gitignore b/mod/emacslisp/.gitignore new file mode 100644 index 0000000..c531d98 --- /dev/null +++ b/mod/emacslisp/.gitignore @@ -0,0 +1 @@ +*.elc diff --git a/emacslisp/fizzbuzz.el b/mod/emacslisp/fizzbuzz.el similarity index 100% rename from emacslisp/fizzbuzz.el rename to mod/emacslisp/fizzbuzz.el diff --git a/javascript/fizzbuzz.js b/mod/javascript/fizzbuzz.js similarity index 100% rename from javascript/fizzbuzz.js rename to mod/javascript/fizzbuzz.js diff --git a/javascript/fizzbuzz2.js b/mod/javascript/fizzbuzz2.js similarity index 100% rename from javascript/fizzbuzz2.js rename to mod/javascript/fizzbuzz2.js diff --git a/javascript/index.html b/mod/javascript/index.html similarity index 100% rename from javascript/index.html rename to mod/javascript/index.html diff --git a/ruby/fizzbuzz.rb b/mod/ruby/fizzbuzz.rb similarity index 100% rename from ruby/fizzbuzz.rb rename to mod/ruby/fizzbuzz.rb diff --git a/sh/fizzbuzz.sh b/mod/sh/fizzbuzz.sh similarity index 100% rename from sh/fizzbuzz.sh rename to mod/sh/fizzbuzz.sh