* as/z80/asexpr.c, as/z80/z80mch.c: re-fixed bugs
[fw/sdcc] / as / z80 / z80mch.c
index 785087487c0b21cfa275db623febbf065a9a28d3..fe999011244ac4ac99d4a8f3dc0b74b030095297 100644 (file)
@@ -1,13 +1,20 @@
-/* z80mch.c */
+/* z80mch.c
 
-/*
- * (C) Copyright 1989-1995
- * All Rights Reserved
- *
- * Alan R. Baldwin
- * 721 Berkeley St.
- * Kent, Ohio  44240
- */
+   Copyright (C) 1989-1995 Alan R. Baldwin
+   721 Berkeley St., Kent, Ohio 44240
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /*
  * Extensions: P. Felber
@@ -30,7 +37,7 @@ VOID
 machine(mp)
 struct mne *mp;
 {
-       register op, t1, t2;
+       register int op, t1, t2;
        struct expr e1, e2;
        int rf, v1, v2;
 
@@ -126,6 +133,7 @@ struct mne *mp;
                        if ((t2 != S_R8) || (e2.e_addr != A))
                                ++t1;
                        comma();
+                       clrexpr(&e2);
                        t2 = addr(&e2);
                }
                if (genop(0xCB, op, &e2, 0) || t1)
@@ -140,6 +148,7 @@ struct mne *mp;
                        if ((t2 != S_R8) || (e2.e_addr != A))
                                ++t1;
                        comma();
+                       clrexpr(&e2);
                        t2 = addr(&e2);
                }
                if (genop(0, op, &e2, 1) || t1)
@@ -542,10 +551,16 @@ struct mne *mp;
        case S_DJNZ:
        case S_JR:
                if ((v1 = admode(CND)) != 0 && rf != S_DJNZ) {
-#else GAMEBOY
+                       if ((v1 &= 0xFF) <= 0x03) {
+                               op += (v1+1)<<3;
+                       } else {
+                               aerr();
+                       }
+                       comma();
+               }
+#else /* GAMEBOY */
        case S_JR:
                if ((v1 = admode(CND)) != 0) {
-#endif /* GAMEBOY */
                        if ((v1 &= 0xFF) <= 0x18) {
                                op += (v1+1)<<3;
                        } else {
@@ -553,11 +568,12 @@ struct mne *mp;
                        }
                        comma();
                }
+#endif /* GAMEBOY */
                expr(&e2, 0);
                outab(op);
                if (e2.e_base.e_ap == NULL || e2.e_base.e_ap == dot.s_area) {
                        v2 = e2.e_addr - dot.s_addr - 1;
-                       if ((v2 < -128) || (v2 > 127))
+                       if (pass == 2 && ((v2 < -128) || (v2 > 127)))
                                aerr();
                        outab(v2);
                } else {