From: j8takagi Date: Mon, 4 Jun 2018 04:15:35 +0000 (+0900) Subject: SUBLのフラグ問題とテストを修正 X-Git-Tag: v0.3p2~2 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf87afdb65ffcb317b7bc9c52c79a29f2936642e;p=YACASL2.git SUBLのフラグ問題とテストを修正 --- diff --git a/as/cmd/ADDL/addl_r_adr__as1.casl b/as/cmd/ADDL/addl_r_adr__as1.casl index 72fbced..5a7abab 100644 --- a/as/cmd/ADDL/addl_r_adr__as1.casl +++ b/as/cmd/ADDL/addl_r_adr__as1.casl @@ -3,6 +3,6 @@ MAIN START LD GR1,A ADDL GR1,B RET -A DC #FFEC ; -20 +A DC #FFEC ; 65516 B DC #000A ; 10 END diff --git a/src/exec.c b/src/exec.c index 3ef778d..074b043 100644 --- a/src/exec.c +++ b/src/exec.c @@ -370,14 +370,15 @@ void addl(WORD r, WORD val) void subl(WORD r, WORD val) { - long s; + unsigned long o, s; - if((s = sys->cpu->gr[r] + (~val + 1)) > 0x10000) { + o = sys->cpu->gr[r]; + if((s = o + (~val + 1)) > 0x10000) { s -= 0x10000; } sys->cpu->gr[r] = (WORD)s; addl_subl_flagset(s); - if(r < val) { + if(o < val) { sys->cpu->fr += OF; } } diff --git a/test/system/casl2_cmd/cmd_addl_r_adr__as1/0.txt b/test/system/casl2_cmd/cmd_addl_r_adr__as1/0.txt index d3b765f..5b187ed 100644 --- a/test/system/casl2_cmd/cmd_addl_r_adr__as1/0.txt +++ b/test/system/casl2_cmd/cmd_addl_r_adr__as1/0.txt @@ -3,7 +3,7 @@ MAIN START LD GR1,A ADDL GR1,B RET -A DC #FFEC ; -20 +A DC #FFEC ; 65516 B DC #000A ; 10 END @@ -20,7 +20,7 @@ Assemble ../../../../as/cmd/ADDL/addl_r_adr__as1.casl (1) #0003 #0006 ../../../../as/cmd/ADDL/addl_r_adr__as1.casl: 5: RET #0004 #8100 -../../../../as/cmd/ADDL/addl_r_adr__as1.casl: 6:A DC #FFEC ; -20 +../../../../as/cmd/ADDL/addl_r_adr__as1.casl: 6:A DC #FFEC ; 65516 #0005 #FFEC ../../../../as/cmd/ADDL/addl_r_adr__as1.casl: 7:B DC #000A ; 10 #0006 #000A @@ -68,7 +68,7 @@ Executing machine codes #0004: GR7: 0 = #0000 = 0000000000000000 #0004: SP: 8 = #0008 = 0000000000001000 #0004: PR: 4 = #0004 = 0000000000000100 -#0004: FR (OF SF ZF): 110 +#0004: FR (OF SF ZF): 010 #0004: Memory:::: #0004: adr : 0000 0001 0002 0003 0004 0005 0006 0007 #0004: 0000: 1010 0005 2210 0006 8100 FFEC 000A 0000 diff --git a/test/system/casl2_cmd/cmd_subl_r_adr__as1/0.txt b/test/system/casl2_cmd/cmd_subl_r_adr__as1/0.txt index 3ad2aea..5a311a6 100644 --- a/test/system/casl2_cmd/cmd_subl_r_adr__as1/0.txt +++ b/test/system/casl2_cmd/cmd_subl_r_adr__as1/0.txt @@ -68,7 +68,7 @@ Executing machine codes #0004: GR7: 0 = #0000 = 0000000000000000 #0004: SP: 8 = #0008 = 0000000000001000 #0004: PR: 4 = #0004 = 0000000000000100 -#0004: FR (OF SF ZF): 010 +#0004: FR (OF SF ZF): 110 #0004: Memory:::: #0004: adr : 0000 0001 0002 0003 0004 0005 0006 0007 #0004: 0000: 1010 0005 2310 0006 8100 FFEC FFF6 0000 diff --git a/test/system/casl2_cmd/cmd_subl_r_adr__o/0.txt b/test/system/casl2_cmd/cmd_subl_r_adr__o/0.txt index 92cbcc6..640855f 100644 --- a/test/system/casl2_cmd/cmd_subl_r_adr__o/0.txt +++ b/test/system/casl2_cmd/cmd_subl_r_adr__o/0.txt @@ -1,4 +1,4 @@ -;;; SUBL r,adr 算術減算ではオーバーフロー、論理演算ではオーバーフローなし +;;; SUBL r,adr 論理演算ではオーバーフローなし(算術減算ではオーバーフロー) MAIN START LD GR1,A SUBL GR1,B @@ -10,7 +10,7 @@ B DC #7FFF ; 32767 Assemble ../../../../as/cmd/SUBL/subl_r_adr__o.casl (0) Assemble ../../../../as/cmd/SUBL/subl_r_adr__o.casl (1) -../../../../as/cmd/SUBL/subl_r_adr__o.casl: 1:;;; SUBL r,adr 算術減算ではオーバーフロー、論理演算ではオーバーフローなし +../../../../as/cmd/SUBL/subl_r_adr__o.casl: 1:;;; SUBL r,adr 論理演算ではオーバーフローなし(算術減算ではオーバーフロー) ../../../../as/cmd/SUBL/subl_r_adr__o.casl: 2:MAIN START ../../../../as/cmd/SUBL/subl_r_adr__o.casl: 3: LD GR1,A #0000 #1010