割算方式とカウンタ方式でディレクトリを分割
authorj8takagi <info@j8takagi.net>
Fri, 2 Nov 2012 11:06:09 +0000 (20:06 +0900)
committerj8takagi <info@j8takagi.net>
Fri, 2 Nov 2012 11:06:09 +0000 (20:06 +0900)
25 files changed:
cnt/c/Makefile [new file with mode: 0644]
cnt/c/fizzbuzz.c [moved from c/fizzbuzz2.c with 100% similarity]
cnt/casl/.gitignore [moved from casl/.gitignore with 100% similarity]
cnt/casl/casl2lib/abs.casl [moved from casl/casl2lib/abs.casl with 100% similarity]
cnt/casl/casl2lib/divl.casl [moved from casl/casl2lib/divl.casl with 100% similarity]
cnt/casl/casl2lib/outl.casl [moved from casl/casl2lib/outl.casl with 100% similarity]
cnt/casl/casl2lib/rev.casl [moved from casl/casl2lib/rev.casl with 100% similarity]
cnt/casl/fizzbuzz.casl [moved from casl/fizzbuzz2.casl with 100% similarity]
cnt/emacslisp/.gitignore [moved from emacslisp/.gitignore with 100% similarity]
cnt/ruby/fizzbuzz.rb [moved from ruby/fizzbuzz2.rb with 100% similarity]
mod/c/Makefile [moved from c/Makefile with 100% similarity]
mod/c/fizzbuzz.c [moved from c/fizzbuzz.c with 100% similarity]
mod/casl/.gitignore [new file with mode: 0644]
mod/casl/casl2lib/abs.casl [new file with mode: 0644]
mod/casl/casl2lib/divl.casl [new file with mode: 0644]
mod/casl/casl2lib/outl.casl [new file with mode: 0644]
mod/casl/casl2lib/rev.casl [new file with mode: 0644]
mod/casl/fizzbuzz.casl [moved from casl/fizzbuzz.casl with 100% similarity]
mod/emacslisp/.gitignore [new file with mode: 0644]
mod/emacslisp/fizzbuzz.el [moved from emacslisp/fizzbuzz.el with 100% similarity]
mod/javascript/fizzbuzz.js [moved from javascript/fizzbuzz.js with 100% similarity]
mod/javascript/fizzbuzz2.js [moved from javascript/fizzbuzz2.js with 100% similarity]
mod/javascript/index.html [moved from javascript/index.html with 100% similarity]
mod/ruby/fizzbuzz.rb [moved from ruby/fizzbuzz.rb with 100% similarity]
mod/sh/fizzbuzz.sh [moved from sh/fizzbuzz.sh with 100% similarity]

diff --git a/cnt/c/Makefile b/cnt/c/Makefile
new file mode 100644 (file)
index 0000000..f271073
--- /dev/null
@@ -0,0 +1,12 @@
+CC ?= gcc
+CFLAGS ?= -g -Wall -Wextra
+
+.PHONY: all clean
+
+all: fizzbuzz
+
+fizzbuzz: fizzbuzz.c
+       $(CC) $(CFLAGS) -o $@  $^
+
+clean:
+       @$(RMF) fizzbuzz
similarity index 100%
rename from c/fizzbuzz2.c
rename to cnt/c/fizzbuzz.c
similarity index 100%
rename from casl/.gitignore
rename to cnt/casl/.gitignore
similarity index 100%
rename from casl/fizzbuzz2.casl
rename to cnt/casl/fizzbuzz.casl
similarity index 100%
rename from ruby/fizzbuzz2.rb
rename to cnt/ruby/fizzbuzz.rb
similarity index 100%
rename from c/Makefile
rename to mod/c/Makefile
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 (file)
index 0000000..5761abc
--- /dev/null
@@ -0,0 +1 @@
+*.o
diff --git a/mod/casl/casl2lib/abs.casl b/mod/casl/casl2lib/abs.casl
new file mode 100644 (file)
index 0000000..be0b922
--- /dev/null
@@ -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 (file)
index 0000000..3591366
--- /dev/null
@@ -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 (file)
index 0000000..a2967d8
--- /dev/null
@@ -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 (file)
index 0000000..397c5c4
--- /dev/null
@@ -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
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 (file)
index 0000000..c531d98
--- /dev/null
@@ -0,0 +1 @@
+*.elc
similarity index 100%
rename from ruby/fizzbuzz.rb
rename to mod/ruby/fizzbuzz.rb
similarity index 100%
rename from sh/fizzbuzz.sh
rename to mod/sh/fizzbuzz.sh