Menu

#3376 SWAPC error

closed-fixed
pdk14 (2)
other
5
2022-12-15
2022-03-31
No

SDCC 4.2.0 #13081 (MINGW64)
sdcc -mpdk14 test.c

__sfr __at(0x10)    _pa;
#define PA          _pa

volatile char foo;
void main() {
    for(;;) {
        __asm;
            sr          _foo
            swapc.io    __pa, #0
        __endasm;
        if (PA&1) foo ^= 0x8e;  //lfsr
    }
}

got "test.asm:111: Error: machine specific addressing or addressing mode error"

Discussion

  • Konstantin Kim

    Konstantin Kim - 2022-09-26

    can someone reproduce/confirm the bug ?

     
    • Philipp Klaus Krause

      I can reproduce the issue using sdcc from current svn on my amd64 Debian GNU/Linux testing system. I suspect this could be fixed in the assembler relatively easily, by what is different for swapc vs. other instructions that have an .io variant. But I don't know, and I'm not that familiar with the assemblers. Patches are welcome.

       
  • Free-PDK

    Free-PDK - 2022-12-14

    looks like the assembler emit function for swapc was called with plain op (without the extra options) and therefore the mandatory falg "PDK_OPCODE_ADR_IO" was not present.

    patch for pdk14 and pdk15 (pdk13 does not have swapc and pdk16 implementation is missing it):

    % svn diff
    Index: aspdk14/pdk14mch.c
    ===================================================================
    --- aspdk14/pdk14mch.c  (revision 13761)
    +++ aspdk14/pdk14mch.c  (working copy)
    @@ -222,7 +222,7 @@
    
             case S_SWAPC:
                   def.mask = 0x3F;
    
    -              eswapc(op, def, /*N offset*/6);
    +              eswapc(opWithFlags, def, /*N offset*/6);
                   break;
    
             case S_COMP:
    Index: aspdk15/pdk15mch.c
    ===================================================================
    --- aspdk15/pdk15mch.c  (revision 13761)
    +++ aspdk15/pdk15mch.c  (working copy)
    @@ -219,7 +219,7 @@
    
             case S_SWAPC:
                   def.mask = 0x7F;
    
    -              eswapc(op, def, /*N offset*/7);
    +              eswapc(opWithFlags, def, /*N offset*/7);
                   break;
    
             case S_COMP:
    
     
    👍
    1
    • Philipp Klaus Krause

      Thanks. the patch looks good to me (though I am not an assembler expert), and regression tests pass (but they don't use swapc anyway).
      I've applied the patch in [r13768].
      It would be good if someone finishes the pdk16 assembler and linker. Nikolas, who did most of the work on pdk assemblers and linkers AFAIK isn't around anymore.

       

      Related

      Commit: [r13768]

  • Philipp Klaus Krause

    • status: open --> pending-fixed
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Please check if the fix in [r13768] works for you.

     

    Related

    Commit: [r13768]

  • Konstantin Kim

    Konstantin Kim - 2022-12-15

    thanks, it works

     
  • Philipp Klaus Krause

    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB