Menu

#3638 asrab doesn't differentiate between AF and AF'

closed-fixed
None
sdas
5
2023-08-26
2023-08-25
D-mo
No

The following program:

void main() __naked
{
__asm
    push af
    push af'    ; invalid

    pop af
    pop af'     ; invalid

    ex af, af   ; invalid
    ex af, af'
    ex af', af  ; invalid
    ex af', af' ; invalid
__endasm;
}

accepts invalid instructions and generates the following opcodes:

0000       48 _main::
           49 ;main.c:14: __endasm;
0000 F5    50  push af
0001 F5    51  push af'    ; invalid
0002 F1    52  pop af
0003 F1    53  pop af'     ; invalid
0004 08    54  ex af, af   ; invalid
0005 08    55  ex af, af'
0006 08    56  ex af', af  ; invalid
0007 08    57  ex af', af' ; invalid
           58 ;main.c:15: }

The program was compiled with this command:

sdcc -mr3ka main.c

Related

Wiki: NGI0-Entrust-SDCC

Discussion

  • D-mo

    D-mo - 2023-08-25

    sdcc version is 4.2

     
  • D-mo

    D-mo - 2023-08-25

    The following patch fixes the problem for me. Could someone please review it to make sure I didn't miss anything?

    From d810ae49a52e61cd379abfd523eff55a2fd3a27b Mon Sep 17 00:00:00 2001
    From: Dimitry Ishenko <dimitry.ishenko@gmail.com>
    Date: Thu, 24 Aug 2023 22:47:33 -0400
    Subject: [PATCH] [asrab] Differentiate between AF and AF'
    
    This is done by splitting R16X into R16AF and R16AF_ALT. As a result,
    asrab now correctly rejects the following instructions:
    
    
        * push af'
        * pop af'
        * ex af, af
        * ex af', af
        * ex af', af'
    ---
     sdas/asrab/rab.h    |  8 ++++++--
     sdas/asrab/rabadr.c | 23 +++++++++++++++++------
     sdas/asrab/rabmch.c |  4 ++--
     3 files changed, 25 insertions(+), 10 deletions(-)
    
    diff --git a/sdas/asrab/rab.h b/sdas/asrab/rab.h
    index fd866cd3..02846158 100644
    --- a/sdas/asrab/rab.h
    +++ b/sdas/asrab/rab.h
    @@ -123,7 +123,7 @@
     #define S_R8X           32
    
     #define S_R16           34
    -#define S_R16X          35
    +
     #define S_CND           36
     #define S_FLAG          37
    
    @@ -131,6 +131,9 @@
     #define S_R32_JKHL      39
     #define S_RXPC          40
    
    +#define S_R16AF         41
    +#define S_R16AF_ALT     42
    +
     /*
    
      * Indexing modes
      */
    @@ -225,7 +228,8 @@ extern  struct  adsym   R8[];
     extern  struct  adsym   R8X[];
     extern  struct  adsym   R8IP[];
     extern  struct  adsym   R16[];
    -extern  struct  adsym   R16X[];
    +extern  struct  adsym   R16AF[];
    +extern  struct  adsym   R16AF_ALT[];
    
     extern  struct  adsym   R32_JKHL[];
     extern  struct  adsym   R32_BCDE[];
    diff --git a/sdas/asrab/rabadr.c b/sdas/asrab/rabadr.c
    index f357dba5..295751d6 100644
    --- a/sdas/asrab/rabadr.c
    +++ b/sdas/asrab/rabadr.c
    @@ -85,8 +85,12 @@ struct expr *esp;
                             mode = S_R8X;
                             aerr();
                     } else
    
    -                if ((indx = admode(R16X)) != 0) {
    -                        mode = S_R16X;
    +                if ((indx = admode(R16AF_ALT)) != 0) {
    +                        mode = S_R16AF_ALT;
    +                        aerr();
    +                } else
    +                if ((indx = admode(R16AF)) != 0) {
    +                        mode = S_R16AF;
                             aerr();
                     } else
                     if ((indx = admode(R16)) != 0) {
    @@ -126,8 +130,11 @@ struct expr *esp;
                     if ((indx = admode(R8X)) != 0) {
                             mode = S_R8X;
                     } else
    -                if ((indx = admode(R16X)) != 0) {
    -                        mode = S_R16X;
    +                if ((indx = admode(R16AF_ALT)) != 0) {
    +                        mode = S_R16AF_ALT;
    +                } else
    +                if ((indx = admode(R16AF)) != 0) {
    +                        mode = S_R16AF;
                     } else
                     if ((indx = admode(R16)) != 0) {
                             mode = S_R16;
    @@ -263,12 +270,16 @@ struct  adsym   R16[] = {
         {   "",     0000    }
     };
    
    -struct  adsym   R16X[] = {
    
    -    {   "af'",  AF|0400 },      /* af' must be first !!! */
    +struct  adsym   R16AF[] = {
         {   "af",   AF|0400 },
         {   "",     0000    }
     };
    
    +struct  adsym   R16AF_ALT[] = {
    
    +    {   "af'",  AF|0400 },
    +    {   "",     0000    }
    +};
    +
     struct  adsym   R32_BCDE[] = {
       {   "bcde",   BCDE|0400 },
       {   "",       0000      }
    diff --git a/sdas/asrab/rabmch.c b/sdas/asrab/rabmch.c
    index 1f707c09..0ab5dd43 100644
    --- a/sdas/asrab/rabmch.c
    +++ b/sdas/asrab/rabmch.c
    @@ -124,7 +124,7 @@ VOID  machine(struct mne * mp)
                     break;
    
             case S_PUSH:
    
    -                if (admode(R16X)) {
    +                if (admode(R16AF)) {
                             outab(op+0x30);
                             break;
                     } else if ((v1 = admode(R8IP)) != 0) {
    @@ -821,7 +821,7 @@ VOID  machine(struct mne * mp)
                                     }
                             }
                     }
    -                if ((t1 == S_R16X) && (t2 == S_R16X)) {
    +                if ((t1 == S_R16AF) && (t2 == S_R16AF_ALT)) {
                             outab(0x08);
                             break;
                     }
    -- 
    2.39.2
    
     

    Last edit: D-mo 2023-08-25
  • D-mo

    D-mo - 2023-08-25

    With this patch the compiler now correctly rejects five invalid instructions:

    user@linux:~/digi/$ sdcc -mr3ka main.c 
    main.c:5:12: warning: missing terminating ' character
    main.c:8:11: warning: missing terminating ' character
    main.c:11:14: warning: missing terminating ' character
    main.c:12:10: warning: missing terminating ' character
    main.asm:51: Error: <q> missing or improper operators, terminators, or delimiters
    main.asm:53: Error: <q> missing or improper operators, terminators, or delimiters
    main.asm:54: Error: <a> machine specific addressing or addressing mode error
    main.asm:56: Error: <a> machine specific addressing or addressing mode error
    main.asm:57: Error: <a> machine specific addressing or addressing mode error
    removing main.rel
    
     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
    • Category: other --> sdas
     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Philipp Klaus Krause

    Thanks. Fixed in [r14320] by applying your patch.

     

    Related

    Commit: [r14320]


Log in to post a comment.

MongoDB Logo MongoDB