From c9a6eaa0b802459a7f62d15510c9676664b3a51d Mon Sep 17 00:00:00 2001 From: j8takagi Date: Wed, 24 Feb 2010 21:34:43 +0900 Subject: [PATCH] =?utf8?q?=E6=95=B0=E5=80=A4=E5=85=A5=E5=8A=9B=E7=94=A8?= =?utf8?q?=E3=81=AECASL2=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA?= =?utf8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit inl.caslとstr2lを分離 エラー処理を修正 --- as/casl2lib/.gitignore | 3 +- as/casl2lib/Makefile | 5 ++- as/casl2lib/src_inl/inl_main.casl | 62 +++++++-------------------- as/casl2lib/src_str2l/str2l_main.casl | 62 +++++++++++++++++++++++++++ as/casl2lib/test/inl/0.txt | 5 ++- as/casl2lib/test/inl/Makefile | 2 +- as/casl2lib/test/inl/inl.casl | 7 ++- as/casl2lib/test/inl/teststr.txt | 6 ++- 8 files changed, 97 insertions(+), 55 deletions(-) create mode 100644 as/casl2lib/src_str2l/str2l_main.casl diff --git a/as/casl2lib/.gitignore b/as/casl2lib/.gitignore index c2862b0..8971ef6 100644 --- a/as/casl2lib/.gitignore +++ b/as/casl2lib/.gitignore @@ -3,4 +3,5 @@ l2str.casl mula.casl outa.casl outb.casl -outl.casl \ No newline at end of file +outl.casl +str2l.casl diff --git a/as/casl2lib/Makefile b/as/casl2lib/Makefile index c77731e..80a43fe 100644 --- a/as/casl2lib/Makefile +++ b/as/casl2lib/Makefile @@ -2,7 +2,7 @@ ECHOHEADER = 'echo ";;; *** This file is auto generated. ***"' TARGETS = inl.casl l2str.casl mula.casl outa.casl outb.casl outl.casl .PHONY: all clean all: $(TARGETS) -inl.casl: src_inl/inl_main.casl mull.casl +inl.casl: src_inl/inl_main.casl str2l.casl @echo ";;; *** This file is auto generated. ***" >$@; \ cat $^ >>$@ l2str.casl: src_l2str/l2str_main.casl divl.casl rev.casl @@ -20,5 +20,8 @@ outb.casl: src_outb/outb_main.casl divl.casl rev.casl outl.casl: src_outl/outl_main.casl l2str.casl @echo ";;; *** This file is auto generated. ***" >$@; \ cat $^ >>$@ +str2l.casl: src_str2l/str2l_main.casl mull.casl + @echo ";;; *** This file is auto generated. ***" >$@; \ + cat $^ >>$@ clean: @for target in $(TARGETS); do rm -f $$target; done diff --git a/as/casl2lib/src_inl/inl_main.casl b/as/casl2lib/src_inl/inl_main.casl index 84a78e9..20237e4 100644 --- a/as/casl2lib/src_inl/inl_main.casl +++ b/as/casl2lib/src_inl/inl_main.casl @@ -1,54 +1,22 @@ ;;; 0〜65535の範囲にある整数の入力を受け付ける ;;; 入力 (SVC) -;;; 出力 GR1: 入力された数値 GR0: 文字の長さ。入力が数字以外の場合は、#FFFF +;;; 出力 GR1: 入力された数値 +;;; GR0: 文字列の長さ。入力が数字以外の場合は、#FFFF ;;; 65536以上の正数が入力された場合はエラー INL START - PUSH 0,GR2 - PUSH 0,GR3 - PUSH 0,GR4 IN IBUF,ILEN ; 入力文字列を格納 - LD GR0,ILEN ; ILEN = 0の場合、FINへジャンプ - JZE FIN ; ↓ - XOR GR1,GR1 ; GR1:各桁の数値 初期化 - LAD GR2,10 ; GR2:10進数の「10」 初期化 - LAD GR3,0 ; GR3:値の一時格納 初期化 - LAD GR4,0 ; GR4:インデックス 初期化 -STOL CPL GR4,ILEN ; ループ先頭。(GR4 = ILEN)の場合、ループ脱出 - JZE CP ; ↓ - LD GR1,IBUF,GR4 ; GR1に、入力文字列中の次の桁を格納 - CPL GR1,ZERO ; (GR1 < '0')の場合、NANへジャンプ - JMI NAN ; ↓ - CPL GR1,NINE ; (GR1 > '9')の場合、NANへジャンプ - JPL NAN ; ↓ - SUBL GR1,ZERO ; GR1の文字を、対応する数値に変換 - ST GR4,NLEN ; GR4 <- ILEN - NLEN - 1 - LD GR4,ILEN ; ↓ - SUBA GR4,NLEN ; ↓ -MUL10 CPA GR4,=1 ; ループ先頭。GR1 <- 10 ** GR4 - JZE NEXT ; (GR4 = 1)の場合、ループ脱出 - JMI NEXT ; ↓ - CALL MULL ; MULLを呼び出し、GR0 <- GR1 * GR2 - JOV FIN ; ↓ - LD GR1,GR0 ; GR1 <- GR0 - LAD GR4,-1,GR4 ; GR4 <- GR4 -1 - JUMP MUL10 ; ループ終端 -NEXT LD GR4,NLEN ; GR4 <- NLEN。復元 - ADDL GR3,GR1 ; GR3 <- GR3 + GR1 - JOV FIN ; ↓ - LAD GR4,1,GR4 ; GR4 <- GR4 + 1 - JUMP STOL ; ループ終端 -NAN LAD GR0,#FFFF ; GR0 <- #FFFF - JUMP FIN ; FINへジャンプ -CP LD GR1,GR3 ; GR0 <- GR3 - LD GR0,ILEN ; GR0 <- ILEN -FIN POP GR4 - POP GR3 - POP GR2 - RET -ZERO DC '0' -NINE DC '9' -IBUF DS 5 + LAD GR1,IBUF + LD GR2,ILEN + CPA GR2,LENMAX + JPL LENOV + CALL STR2L + JOV FIN + LD GR0,GR2 + JUMP FIN +LENOV LAD GR0,#FFFF + SRA GR0,1 +FIN RET ILEN DS 1 -NLEN DS 1 +LENMAX DC 5 +IBUF DS 5 END - diff --git a/as/casl2lib/src_str2l/str2l_main.casl b/as/casl2lib/src_str2l/str2l_main.casl new file mode 100644 index 0000000..70532d3 --- /dev/null +++ b/as/casl2lib/src_str2l/str2l_main.casl @@ -0,0 +1,62 @@ +;;; 0〜65535の範囲にある整数の入力を受け付ける +;;; 10進数の整数を表す文字列を数値に変換 +;;; 入力 GR1: 文字列を格納するアドレス +;;; GR2: 文字列の長さ。1-5を想定 +;;; 出力 GR0: 数値(0〜65535) +;;; 文字列が長過ぎる場合や数値以外の場合は、GR2に#FFFFを格納 +STR2L START + PUSH 0,GR3 + PUSH 0,GR4 + XOR GR0,GR0 ; GR0:初期化 + AND GR2,GR2 ; (GR2 = 0)の場合、FINへジャンプ + JZE FIN ; ↓ + CPL GR2,MAXLEN ; (GR2 > MAXLEN)の場合、LENOVへジャンプ + JPL LENOV ; ↓ + ST GR1,STR ; STR <- GR1 文字列の開始アドレス + ST GR2,LEN ; LEN <- GR2 + LAD GR2,10 ; GR2:10進数の「10」 + XOR GR3,GR3 ; GR3:値の一時格納 + XOR GR4,GR4 ; GR4:インデックス +STOL CPL GR4,LEN ; ループ先頭。(GR4 = LEN)の場合、ループ脱出 + JZE CP ; ↓ + LD GR1,STR ; GR1に、入力文字列中の次の桁を格納 + ADDL GR1,GR4 ; ↓ + LD GR1,0,GR1 ; ↓ + CPL GR1,ZERO ; (GR1 < '0')の場合、NANへジャンプ + JMI NAN ; ↓ + CPL GR1,NINE ; (GR1 > '9')の場合、NANへジャンプ + JPL NAN ; ↓ + SUBL GR1,ZERO ; GR1の文字を、対応する数値に変換 + ST GR4,NLEN ; GR4 <- LEN - NLEN - 1 + LD GR4,LEN ; ↓ + SUBA GR4,NLEN ; ↓ +MUL10 CPA GR4,=1 ; ループ先頭。GR1 <- 10 ** GR4 + JZE NEXT ; (GR4 = 1)の場合、ループ脱出 + JMI NEXT ; ↓ + CALL MULL ; MULLを呼び出し、GR0 <- GR1 * GR2 + JOV FIN ; ↓ + LD GR1,GR0 ; GR1 <- GR0 + LAD GR4,-1,GR4 ; GR4 <- GR4 -1 + JUMP MUL10 ; ループ終端 +NEXT LD GR4,NLEN ; GR4 <- NLEN。復元 + ADDL GR3,GR1 ; GR3 <- GR3 + GR1 + JOV FIN ; ↓ + LAD GR4,1,GR4 ; GR4 <- GR4 + 1 + JUMP STOL ; ループ終端 +NAN LAD GR2,#FFFF ; GR2 <- #FFFF + JUMP FIN ; FINへジャンプ +CP LD GR1,GR3 ; GR0 <- GR3 + LD GR0,LEN ; GR0 <- LEN + JUMP FIN +LENOV LAD GR0,#FFFF + SRA GR0,1 +FIN POP GR4 + POP GR3 + RET +ZERO DC '0' +NINE DC '9' +MAXLEN DC 10 ; 10桁の数値まで入力可能 +STR DS 1 +LEN DS 1 +NLEN DS 1 + END diff --git a/as/casl2lib/test/inl/0.txt b/as/casl2lib/test/inl/0.txt index e0c6218..cb4e0e4 100644 --- a/as/casl2lib/test/inl/0.txt +++ b/as/casl2lib/test/inl/0.txt @@ -1,4 +1,4 @@ -../../../../casl2 -M640 inl.casl ../../../../as/casl2lib/inl.casl ../../../../as/casl2lib/outl.casl +../../../../casl2 -M720 inl.casl ../../../../as/casl2lib/inl.casl ../../../../as/casl2lib/outl.casl 0 1 2 @@ -9,6 +9,7 @@ 65535 Over 65535 Over 65535 -Over 65535 Not A Number Not A Number +12345 +Str too long. Stop diff --git a/as/casl2lib/test/inl/Makefile b/as/casl2lib/test/inl/Makefile index ede7252..529d51d 100644 --- a/as/casl2lib/test/inl/Makefile +++ b/as/casl2lib/test/inl/Makefile @@ -1,6 +1,6 @@ YACASL2DIR= ../../../.. CASL2 = $(YACASL2DIR)/casl2 -CASL2FLAG = -M640 +CASL2FLAG = -M720 LIBDIR = $(YACASL2DIR)/as/casl2lib ASFILE = inl.casl $(LIBDIR)/inl.casl $(LIBDIR)/outl.casl IN = teststr.txt diff --git a/as/casl2lib/test/inl/inl.casl b/as/casl2lib/test/inl/inl.casl index b76c51f..28c6a9c 100644 --- a/as/casl2lib/test/inl/inl.casl +++ b/as/casl2lib/test/inl/inl.casl @@ -8,13 +8,18 @@ LOOP CALL INL ; GR1に数値、GR0に文字列の長さ JZE NAN CALL OUTL JUMP LOOP -OV OUT OVMSG,MLEN1 +OV CPL GR0,=#FFFF + JZE LENOV + OUT OVMSG,MLEN1 JUMP LOOP NAN OUT NANMSG,MLEN2 JUMP LOOP +LENOV OUT LENOVMSG,MLEN3 FIN RET OVMSG DC 'Over 65535' MLEN1 DC 10 NANMSG DC 'Not A Number' MLEN2 DC 12 +LENOVMSG DC 'Str too long. Stop' +MLEN3 DC 18 END diff --git a/as/casl2lib/test/inl/teststr.txt b/as/casl2lib/test/inl/teststr.txt index 0054244..b6b862a 100644 --- a/as/casl2lib/test/inl/teststr.txt +++ b/as/casl2lib/test/inl/teststr.txt @@ -8,6 +8,8 @@ 65535 65536 90000 -100000 -1 -NOTNUMBER +NOTNU +12345 +100000 +1234 -- 2.18.0