This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Strange behavior of MPY instruction (C5505)

Hi, I've written set of c-callable assembler functions. The purpose was to make some fractional arithmetic faster, however now it's mostly curiosity why it's not working. I have functions for adding, subtracting, multiplying etc. All of them look quite similar: set status registers ,copy 1st arg from T0 to AC0, make certain arithmetic and store result in AC0, shift AC0 (Q15), store return result in T0,restore status register to their previous state. ADD and SUB are working fine, but when using MPY instruction result in AC0 is always zero, for any arguments. I'm not talking about return value, I've checked in debuger, that right after MPY instruction AC0 is zero. I have even tried to make multiplying by constant (MPYK #2,AC0), and it's still zero. Source code is below. Status register initialization is same as in DSPLIB mul32 function, but other combinations was also tested.  Hope that someone have some assembler experience and can tell what is going on. 

Thanks in advance

C:

extern Int16 fmul(Int16,Int16);

ASM:

    .def _fmul
     .cpl_on
     .arms_on
     .c54cm_off
   
     .text

_fmul:

    PSH    mmap(ST3_55)

    PSH    mmap(ST2_55)

    PSH    mmap(ST1_55)

    PSH    mmap(ST0_55)

    AND    #001FFh, mmap(ST0_55)    ;clear all ACOVx,TC1, TC2, C
    OR    #04140h, mmap(ST1_55)    ;set CPL, SXMD, FRCT
    AND    #0F9DFh, mmap(ST1_55)    ;clear M40, SATD, 54CM
    AND #07A00h, mmap(ST2_55)    ;clear ARMS, RDM, CDPLC, AR[0-7]LC
    AND    #0FFDDh, mmap(ST3_55)    ;clear SATA, SMUL
   
    MOV T0,AC0
    MPY T1,AC0       ; <- thats feral instruction
    SFTA AC0,# -15
    MOV AC0,T0
   
    POP mmap(ST0_55)

    POP mmap(ST1_55)

    POP mmap(ST2_55)

    POP mmap(ST3_55)
    RET