サンプルに、count1とcall_count1を追加
authorj8takagi <j8takagi@nifty.com>
Thu, 7 Jun 2018 12:55:35 +0000 (21:55 +0900)
committerj8takagi <j8takagi@nifty.com>
Thu, 7 Jun 2018 12:55:35 +0000 (21:55 +0900)
as/sample/call_count1.casl [new file with mode: 0644]
as/sample/count1.casl [new file with mode: 0644]

diff --git a/as/sample/call_count1.casl b/as/sample/call_count1.casl
new file mode 100644 (file)
index 0000000..7001296
--- /dev/null
@@ -0,0 +1,5 @@
+MAIN    START
+        LAD     GR1,32764
+        CALL    COUNT1
+        RET
+        END
diff --git a/as/sample/count1.casl b/as/sample/count1.casl
new file mode 100644 (file)
index 0000000..d9f4837
--- /dev/null
@@ -0,0 +1,18 @@
+COUNT1  START                    ;
+;       入力    ; GR1:検索する語
+;       処理    ; GR1 中の'1'のビットの個数を求める
+;       出力    ; GR0:GR1 中の'1'のビットの個数
+        PUSH    0,GR1            ;
+        PUSH    0,GR2            ;
+        SUBA    GR2,GR2          ; Count = 0
+        AND     GR1,GR1          ; 全部のビットが'0'?
+        JZE     RETURN           ; 全部のビットが'0'なら終了
+MORE    LAD     GR2,1,GR2        ; Count = Count + 1
+        LAD     GR0,-1,GR1       ; 最下位の'1'のビット 1 個を
+        AND     GR1,GR0          ; '0'に変える
+        JNZ     MORE             ; '1'のビットが残っていれば繰返し
+RETURN  LD      GR0,GR2          ; GR0 = Count
+        POP     GR2              ;
+        POP     GR1              ;
+        RET                      ; 呼出しプログラムへ戻る
+        END                      ;