• AVR Freaks

Helpful ReplyHot!Disassembly to ASM the hard way

Author
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
2020/12/02 22:55:48 (permalink)
0

Disassembly to ASM the hard way

HI guys
trying ASM and in-lining everything including the MUL call
all varibles have been defined in main
see if it makes sense
99: for (i = 0; i < Ni; i++) {
0080 01F1 CLRF i                   asm("CLRF _i ");
                                   asm("GOTO I_START"); // will untangle later
                                   asm("I_LOOP:");
         
00BF 3017 MOVLW 0x17            asm("MOVLW 0x17 "); // 23 ok
00C0 0AF1 INCF i, F             asm("INCF _i, F");
00C1 0271 SUBWF i, W            asm("SUBWF _i, W");
00C2 1C03 BTFSS STATUS, 0x0     asm("BTFSC STATUS, 0x0"); <<<<< changed
00C3 2881 GOTO 0x81             asm("GOTO I_END"); //        to fall through
100: multiplier = X[tp--];
                               asm("I_START:");
0081 3573 LSLF tp, W           asm("LSLF _tp, W ");
0082 3E20 ADDLW 0x20           asm("ADDLW 0x20 ");
0083 0086 MOVWF FSR1           asm("MOVWF FSR1 ");
0084 0187 CLRF FSR1H           asm("CLRF FSR1H ");
0085 3F40 MOVIW [0]FSR1        asm("MOVIW [0]FSR1");
0086 00E5 MOVWF multiplier     asm("MOVWF _multiplier+0"); // << adr 0x65
0087 3F41 MOVIW [1]FSR1        asm("MOVIW [1]FSR1 ");
0088 00E6 MOVWF 0x66           asm("MOVWF _multiplier+1");
0089 03F3 DECF tp, F           asm("DECF _tp, F ");
101: multiplicand = C[i];
008A 0871 MOVF i, W             asm("MOVF _i, W ");
008B 0771 ADDWF i, W            asm("ADDWF _i, W ");
008C 0771 ADDWF i, W            asm("ADDWF _i, W ");
008D 3EA0 ADDLW 0xA0            asm("ADDLW 0xA0 "); // ok [32]
008E 0086 MOVWF FSR1            asm("MOVWF FSR1 ");
008F 3F40 MOVIW [0]FSR1         asm("MOVIW [0]FSR1 ");
0090 00DE MOVWF multiplicand    asm("MOVWF _multiplicand+0"); // >> adr 0x5E
0091 3F41 MOVIW [1]FSR1         asm("MOVIW [1]FSR1 ");
0092 00DF MOVWF 0x5F            asm("MOVWF _multiplicand+1");
0093 3F42 MOVIW [2]FSR1         asm("MOVIW [2]FSR1 ");
0094 00E0 MOVWF 0x60            asm("MOVWF _multiplicand+2");
102: multiplicand >>= 1; // adr ref only
0095 37E0 ASRF 0x60, F        asm("ASRF _multiplicand+2,F"); // the real adr
0096 0CDF RRF 0x5F, F         asm("RRF _multiplicand+1,F"); // of multiplicand
0097 0CDE RRF multiplicand, F       asm("RRF _multiplicand+0,F"); // adr 0x5E
103:
104: MUL_tmp = MUL16_24(multiplier,multiplicand);
                   ************ can this part can be dumped ?? ********** 
                   looks like double buffered for same variables ????                                 
0098 0866 MOVF 0x66, W                                asm("MOVF _multiplier+1, W");
0099 00FA MOVWF channel                              asm(" "); // adr 0x7a
009A 0865 MOVF multiplier, W                         asm("MOVF _multiplier+0, W");
009B 00F9 MOVWF InterruptHandler                    asm(" "); // adr 0x79
009C 085E MOVF multiplicand, W                     asm(" ");
009D 00FB MOVWF multiplicand                       asm("MOVWF _multiplicand+0"); // adr 0x7B
009E 085F MOVF 0x5F, W                             asm(" ");
009F 00FC MOVWF 0x7C                             asm("MOVWF _multiplicand+1");
00A0 0860 MOVF 0x60, W                             asm("MOVF 0x60, W ");
00A1 00FD MOVWF 0x7D                             asm("MOVWF _multiplicand+2");

00A2 2129 //CALL 0x129 <<<<<<<<<<<< will not be used <<<<<<<<<<<<<<<<<<<<<<<<<<<<<

and this part is makes no sence the last 4 instructions
128: int32_t MUL16_24(int16_t multiplier, int24_t multiplicand) {
0129 087B MOVF multiplicand, W     asm("MOVF multiplicand+0,W");
012A 00D6 MOVWF factor             asm("MOVWF factor+0 ");
012B 087C MOVF 0x7C, W             asm("MOVF multiplicand+1,W");
012C 00D7 MOVWF 0x57               asm("MOVWF factor+1 ");
012D 087D MOVF 0x7D, W             asm("MOVF multiplicand+2,W");
012E 00D8 MOVWF 0x58               asm("MOVWF factor+2 ");
012F 0D89 RLF WREG, F              asm("RLF WREG,F");       asm("CLRF factor+3 "); // start 0
0130 3B89 SUBWFB WREG, F           asm("SUBWFB WREG,F");    asm("BTFSC factor+2,7"); // bit test for neg
0131 0989 COMF WREG, F             asm("COMF WREG, F ");    asm("DECF factor+3,F"); // sign extend
0132 00D9 MOVWF 0x59       //      asm("MOVWF factor+3 ");
129: factor = multiplicand;
 
the last 4 lines I dont know what it's doing, does my replacement look OK ??? 
can 0x98 - 0xA1 be dumped ?
i think i got the rest of the way
thanks
davea
 
#1
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/03 10:24:08 (permalink)
0 (2)
davea
trying ASM and in-lining everything including the MUL call
all varibles have been defined in main
see if it makes sense
104: MUL_tmp = MUL16_24(multiplier,multiplicand);
                   ************ can this part can be dumped ?? ********** 
                   looks like double buffered for same variables ????                                 
0098 0866 MOVF 0x66, W                                asm("MOVF _multiplier+1, W");
0099 00FA MOVWF channel                              asm(" "); // adr 0x7a
009A 0865 MOVF multiplier, W                         asm("MOVF _multiplier+0, W");
009B 00F9 MOVWF InterruptHandler                    asm(" "); // adr 0x79
009C 085E MOVF multiplicand, W                     asm(" ");
009D 00FB MOVWF multiplicand                       asm("MOVWF _multiplicand+0"); // adr 0x7B
009E 085F MOVF 0x5F, W                             asm(" ");
009F 00FC MOVWF 0x7C                             asm("MOVWF _multiplicand+1");
00A0 0860 MOVF 0x60, W                             asm("MOVF 0x60, W ");
00A1 00FD MOVWF 0x7D                             asm("MOVWF _multiplicand+2");


That looks like saving the (40-bit ?) return value to MUL_tmp. What data type does MUL16_24() return and what data type is MUL_tmp?
 

and this part is makes no sence the last 4 instructions
128: int32_t MUL16_24(int16_t multiplier, int24_t multiplicand) {
0129 087B MOVF multiplicand, W     asm("MOVF multiplicand+0,W");
012A 00D6 MOVWF factor             asm("MOVWF factor+0 ");
012B 087C MOVF 0x7C, W             asm("MOVF multiplicand+1,W");
012C 00D7 MOVWF 0x57               asm("MOVWF factor+1 ");
012D 087D MOVF 0x7D, W             asm("MOVF multiplicand+2,W");
012E 00D8 MOVWF 0x58               asm("MOVWF factor+2 ");
012F 0D89 RLF WREG, F              asm("RLF WREG,F");       asm("CLRF factor+3 "); // start 0
0130 3B89 SUBWFB WREG, F           asm("SUBWFB WREG,F");    asm("BTFSC factor+2,7"); // bit test for neg
0131 0989 COMF WREG, F             asm("COMF WREG, F ");    asm("DECF factor+3,F"); // sign extend
0132 00D9 MOVWF 0x59       //      asm("MOVWF factor+3 ");
129: factor = multiplicand;
 
the last 4 lines I dont know what it's doing, does my replacement look OK ??? 

The last 4 lines perform the sign extension, which your 3-line replacement does more efficiently.
 

can 0x98 - 0xA1 be dumped ?

That depends on whether you need to use it or not in subsequent code.
 
#2
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/03 11:38:41 (permalink)
0
That looks like saving the (40-bit ?) return value to MUL_tmp. What data type does MUL16_24() return and what data type is MUL_tmp?

there both int32_t, I thought it would be simpler to put all variables in main
the part I want to dump is the setup just before the call
and it looks like call tried to double buffer the multiplier and multiplicand  
as there the same names used in main. I will just the real ones in MUL code not caring if they get trashed
and the return setup will also be dumped as the value needed is product
thanks for looking
davea
#3
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/03 12:58:50 (permalink)
0 (2)
davea
there both int32_t, I thought it would be simpler to put all variables in main
the part I want to dump is the setup just before the call
and it looks like call tried to double buffer the multiplier and multiplicand  

The "setup just before the call" is the function prologue, and the second one is the copying of the function argument  "multiplicand" to the auto variable "factor" inside the function.
 

as there the same names used in main. I will just the real ones in MUL code not caring if they get trashed
and the return setup will also be dumped as the value needed is product

They may be the same names, but they are different identifiers to the C compiler, that happen to share and use the same data memory. It seems to me what you wanted is to get rid of the function call and inline the function. Have you tried the inline specifier?
post edited by 1and0 - 2020/12/03 13:16:07
#4
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 11:29:54 (permalink)
0
Have you tried the inline specifier?

no, was unaware of it 
here is what I got
.
#define USE_asm
#ifndef USE_asm
            tp = pt_ADC; // save current pos of new data
            X[pt_ADC++] = temp2; // insert ADC <<<<<<<<<<<<<< 1767 MAX
            if (pt_ADC >= Ni) pt_ADC = 0; // wrap
            ACC = 0;
            for (i = 0; i < Ni; i++) {
                multiplier = X[tp--];
                multiplicand = C[i];
                multiplicand >>= 1;

                MUL_tmp = MUL16_24(multiplier, multiplicand); // MAX in 3535 with 1 shift 1767 no shift C[i]

                MUL_tmp >>= 1; // must be 2, saved 22us !!!!
                MUL_tmp >>= 1; // ^^^^^^^^^^^^
                ACC += MUL_tmp;
                if (tp & 0x80) tp = Ni - 1; // went neg wrap pointer
            }
#else
            // tp = pt_ADC save current pos of new data
            asm("MOVLB 0");
            asm("MOVF _pt_ADC, W");
            asm("MOVWF _tp ");
            
            // X[pt_ADC++] = temp2; // ADC < 1700 MAX
            asm("LSLF _pt_ADC, W ");
            asm("ADDLW 0x20"); // 32 ok buffer size
            asm("MOVWF FSR1L");
            asm("CLRF FSR1H");
            asm("MOVF _temp2+0,W");
            asm("MOVWI [0]FSR1");
            asm("MOVF _temp2+1,W");
            asm("MOVWI [1]FSR1");
            asm("INCF _pt_ADC,F");

            // if (pt_ADC >= Ni) pt_ADC = 0; // wrap
            asm("MOVLW 0x17"); // 23 ok buffer size
            asm("SUBWF _pt_ADC, W");
            asm("BTFSC STATUS, 0x0");
            asm("CLRF _pt_ADC");

            // ACC = 0;
            asm("CLRF _ACC+0");
            asm("CLRF _ACC+1");
            asm("CLRF _ACC+2");
            asm("CLRF _ACC+3");

            // for (i = 0; i < Ni; i++) { code at END of asm
            asm("CLRF _i ");
            asm("I_LOOP:");
            
            // multiplier = X[tp--];
            asm("LSLF _tp, W ");
            asm("ADDLW 0x20 ");
            asm("MOVWF FSR1L ");
            asm("CLRF FSR1H ");
            asm("MOVIW [0]FSR1");
            asm("MOVWF _multiplier+0"); 
            asm("MOVIW [1]FSR1 ");
            asm("MOVWF _multiplier+1");
            asm("DECF _tp, F ");

            // multiplicand = C[i];
            asm("MOVF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDLW 0xA0 "); // <<<<<< ???????
            asm("MOVWF FSR1L ");
            asm("MOVIW [0]FSR1 ");
            asm("MOVWF _multiplicand+0");
            asm("MOVIW [1]FSR1 ");
            asm("MOVWF _multiplicand+1");
            asm("MOVIW [2]FSR1 ");
            asm("MOVWF _multiplicand+2");

            // multiplicand >>= 1 for adr ref only
            asm("ASRF _multiplicand+2,F");
            asm("RRF _multiplicand+1,F");
            asm("RRF _multiplicand+0,F");

            // int32_t MUL16_24 <<<<<<<<<<<<
            // factor = multiplicand;
            asm("MOVF _multiplicand+0,W");
            asm("MOVWF _factor+0 ");
            asm("MOVF _multiplicand+1,W");
            asm("MOVWF _factor+1 ");
            asm("MOVF _multiplicand+2,W");
            asm("MOVWF _factor+2 ");
            asm("CLRF _factor+3 ");
            asm("BTFSC _factor+2,7");
            asm("DECF _factor+3,F");

            // product = 0;
            asm("CLRF _product+0");
            asm("CLRF _product+1");
            asm("CLRF _product+2");
            asm("CLRF _product+3");

            // sign = 0;
            asm("CLRF _sign");

            // if (multiplier < 0) {
            asm("BTFSS _multiplier+1,7");
            asm("GOTO DO_MUL");
            // multiplier = -multiplier;
            asm("COMF _multiplier+0,F");
            asm("COMF _multiplier+1,F");
            asm("INCF _multiplier+0,F");
            asm("BTFSC STATUS,2");
            asm("INCF _multiplier+1,F");
            // sign++;
            asm("INCF _sign, F "); // }
            //*************************************
            asm("DO_MUL:");
            // if (multiplier & 1)
            asm("BTFSS _multiplier+0,0");
            asm("GOTO SKP_ADD");

            // product += factor;
            asm("MOVF _factor+0,W");
            asm("ADDWF _product+0,F");
            asm("MOVF _factor+1,W");
            asm("ADDWFC _product+1,F");
            asm("MOVF _factor+2,W");
            asm("ADDWFC _product+2,F");
            asm("MOVF _factor+3,W");
            asm("ADDWFC _product+3,F");

            // factor <<= 1;
            asm("SKP_ADD:");
            asm("LSLF _factor+0,F");
            asm("RLF _factor+1,F ");
            asm("RLF _factor+2,F ");
            asm("RLF _factor+3,F ");

            // multiplier >>= 1;
            asm("ASRF _multiplier+1,F");
            asm("RRF _multiplier+0, F");

            // } while (multiplier != 0);
            asm("MOVF _multiplier+0,W ");
            asm("IORWF _multiplier+1,W");
            asm("BTFSS STATUS,2");
            asm("GOTO DO_MUL");
            //*************************************
            // if (sign & 1)
            asm("BTFSS _sign,0");
            asm("GOTO SIGN_end ");
            // product = -product;
            asm("COMF _product+0,F"); // negate
            asm("COMF _product+1,F"); // should be better way !!!!
            asm("COMF _product+2,F");
            asm("COMF _product+3,F");
            asm("INCF _product+0,F");
            asm("BTFSC STATUS, 2");
            asm("INCF _product+1,F");
            asm("BTFSC STATUS, 2");
            asm("INCF _product+2,F");
            asm("BTFSC STATUS,2");
            asm("INCF _product+3,F");
            asm("SIGN_end:"); //

            // product >>= 2;
            asm("ASRF _product+3, F");
            asm("RRF _product+2, F");
            asm("RRF _product+1, F");
            asm("RRF _product+0, F");
            asm("ASRF _product+3, F");
            asm("RRF _product+2, F");
            asm("RRF _product+1, F");
            asm("RRF _product+0, F");

            // ACC += product ;
            asm("MOVF _product+0,W");
            asm("ADDWF _ACC+0, F ");
            asm("MOVF _product+1,W");
            asm("ADDWFC _ACC+1, F ");
            asm("MOVF _product+2,W");
            asm("ADDWFC _ACC+2, F ");
            asm("MOVF _product+3,W");
            asm("ADDWFC _ACC+3, F ");

            // if (tp & 0x80) tp = Ni - 1, went neg wrap pointer
            asm("BTFSS _tp,7");
            asm("GOTO I_TEST");
            asm("MOVLW 0x16 ");
            asm("MOVWF _tp ");

            // for (i = 0; i < Ni; i++)
            asm("I_TEST:");
            asm("MOVLW 0x17 "); // 23 OK
            asm("INCF _i, F");
            asm("SUBWF _i, W");
            asm("BTFSS STATUS,0");
            asm("GOTO I_LOOP");
#endif

and it does WORK and 80us faster because I used factor all the way thought and not MUL_tmp
and the prologue was removed as well as return stuff
it does not work opt = 2 free I dont think its a speed issue it's a bank issue
so off to set variables to BANK0 
davea
 
edit: asm("ADDLW 0xA0 "); // <<<<<< ??????? or this could be the reason ???
I know it has something to with address C how to insert directly in code and also FSR1H
post edited by davea - 2020/12/04 11:53:17
#5
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 12:21:24 (permalink)
-1 (1)
asm("ADDLW 0xA0 "); 
I changed to
asm("ADDLW _C "); worked in pro, disassembly showed 0xA0
free has this error
main.c:162:: error: (1356) fixup overflow referencing psect dataBANK2 (0x120) into 1 byte at 0xE52/0x2 -> 0x729 (dist/default/production\TEST.X.production.o 122/0x86)
I think the lookup table moved up in RAM space, and FSRH needs something set 
now Im STUCK... need help...
davea
post edited by davea - 2020/12/04 13:58:31
#6
ric
Super Member
  • Total Posts : 30204
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Disassembly to ASM the hard way 2020/12/04 14:42:59 (permalink)
0
The assembler only ever wants to see the 7-bit offset address of the variable in the argument, so:
asm("ADDLW 0xA0 & 7fh ");
or
asm("ADDLW BANKMASK(0xA0) ");

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 15:57:09 (permalink)
0
That should be
    asm("ADDLW   low(_C)");

and you'll have to include the high byte too.
#8
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 16:26:09 (permalink) ☄ Helpfulby davea 2020/12/05 10:21:08
+1 (1)
Here are some changes (after the // on the right side) that I'd make:

            // tp = pt_ADC save current pos of new data
            asm("MOVLB 0");                                // asm("banksel _pt_ADC");
            asm("MOVF _pt_ADC, W");
            asm("MOVWF _tp ");
            
            // X[pt_ADC++] = temp2; // ADC < 1700 MAX
            asm("LSLF _pt_ADC, W ");
            asm("ADDLW 0x20"); // 32 ok buffer size        // asm("addlw   low(_X) ");
            asm("MOVWF FSR1L");
            asm("CLRF FSR1H");                             // asm("movlw   high(_X)");
                                                           // asm("movwf   FSR1H   ");
            asm("MOVF _temp2+0,W");
            asm("MOVWI [0]FSR1");
            asm("MOVF _temp2+1,W");
            asm("MOVWI [1]FSR1");
            asm("INCF _pt_ADC,F");

            // if (pt_ADC >= Ni) pt_ADC = 0; // wrap
            asm("MOVLW 0x17"); // 23 ok buffer size        // asm("movlw " ___mkstr(Ni));
            asm("SUBWF _pt_ADC, W");                       // assuming #define Ni 23
            asm("BTFSC STATUS, 0x0");
            asm("CLRF _pt_ADC");

            // ACC = 0;
            asm("CLRF _ACC+0");
            asm("CLRF _ACC+1");
            asm("CLRF _ACC+2");
            asm("CLRF _ACC+3");

            // for (i = 0; i < Ni; i++) { code at END of asm
            asm("CLRF _i ");
            asm("I_LOOP:");
            
            // multiplier = X[tp--];
            asm("LSLF _tp, W ");
            asm("ADDLW 0x20 ");                            // asm("addlw   low(_X)  ");
            asm("MOVWF FSR1L ");
            asm("CLRF FSR1H ");                            // asm("movlw   high(_X) ");
                                                           // asm("movwf   FSR1H    ");
            asm("MOVIW [0]FSR1");
            asm("MOVWF _multiplier+0");
            asm("MOVIW [1]FSR1 ");
            asm("MOVWF _multiplier+1");
            asm("DECF _tp, F ");

            // multiplicand = C[i];
            asm("MOVF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDLW 0xA0 "); // <<<<<< ???????          // asm("addlw   low(_C)  ");
            asm("MOVWF FSR1L ");
                                                           // asm("movlw   high(_C) ");
                                                           // asm("movwf   FSR1H    ");
            asm("MOVIW [0]FSR1 ");
            asm("MOVWF _multiplicand+0");                  // asm("movwf   _factor+0");
            asm("MOVIW [1]FSR1 ");
            asm("MOVWF _multiplicand+1");                  // asm("movwf   _factor+1");
            asm("MOVIW [2]FSR1 ");
            asm("MOVWF _multiplicand+2");                  // asm("movwf   _factor+2");

            // multiplicand >>= 1 for adr ref only
            asm("ASRF _multiplicand+2,F");                 // asm("asrf    _factor+2");
            asm("RRF _multiplicand+1,F");                  // asm("rrf     _factor+1");
            asm("RRF _multiplicand+0,F");                  // asm("rrf     _factor+0");

            // int32_t MUL16_24 <<<<<<<<<<<<
            // factor = multiplicand;
            asm("MOVF _multiplicand+0,W");                 // deleted
            asm("MOVWF _factor+0 ");                       // deleted
            asm("MOVF _multiplicand+1,W");                 // deleted
            asm("MOVWF _factor+1 ");                       // deleted
            asm("MOVF _multiplicand+2,W");                 // deleted
            asm("MOVWF _factor+2 ");                       // deleted
            
            asm("CLRF _factor+3 ");
            asm("BTFSC _factor+2,7");
            asm("DECF _factor+3,F");

#9
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 18:07:20 (permalink)
0
OK now its working in free
missed 1 bank0 variable
at full speed 1.2khz instead of 850hz 
theirs 3 questions 
             // multiplicand = C[i];
            asm("MOVF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDLW low(_C)");
            asm("MOVWF FSR1L "); // what if there is an overflow and carry is set ??????
            
            asm("MOVLW high(_C)");
            asm("MOVWF FSR1H ");
            asm("MOVIW [0]FSR1 ");
            asm("MOVWF _multiplicand+0");
            asm("MOVIW [1]FSR1 ");
            asm("MOVWF _multiplicand+1");
            asm("MOVIW [2]FSR1 ");
            asm("MOVWF _multiplicand+2");
            //asm("CLRF FSR1H ");

#2
#define Ni 23 // in main

            // if (pt_ADC >= Ni) pt_ADC = 0; // wrap
            asm("MOVLW 0x17"); // 23 is buffer size
     
           how to get the buffer size into MOVLW
             and _Ni does not work

#3
            // X[pt_ADC++] = temp2; // ADC < 1767 MAX
            asm("LSLF _pt_ADC, W ");
            asm("ADDLW 0x20"); //<<<<<<< 32
            asm("MOVWF FSR1L");
            asm("CLRF FSR1H");

            int16_t X[Ni]
            where the 0x20 comes from ??
            and what label to replace it with if needed

thanks for any answers
after everything is resolved i should have a basic understanding of 8 bit PIC ASM
davea
 
post edited by davea - 2020/12/04 18:11:18
#10
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 18:22:30 (permalink)
0
davea
theirs 3 questions 
             // multiplicand = C[i];
            asm("MOVF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDWF _i, W ");
            asm("ADDLW low(_C)");
            asm("MOVWF FSR1L "); // what if there is an overflow and carry is set ??????
            
            asm("MOVLW high(_C)");
            asm("MOVWF FSR1H ");


For an array[] of size 23, I believe it will be allocated to the same bank. For larger arrays, you will have to handle the overflow into FSRxH.
 

#2
#define Ni 23 // in main

            // if (pt_ADC >= Ni) pt_ADC = 0; // wrap
            asm("MOVLW 0x17"); // 23 is buffer size
     
           how to get the buffer size into MOVLW
             and _Ni does not work


Did you miss my previous post?
 

#3
            // X[pt_ADC++] = temp2; // ADC < 1767 MAX
            asm("LSLF _pt_ADC, W ");
            asm("ADDLW 0x20"); //<<<<<<< 32
            asm("MOVWF FSR1L");
            asm("CLRF FSR1H");

            int16_t X[Ni]
            where the 0x20 comes from ??
            and what label to replace it with if needed

thanks for any answers
after everything is resolved i should have a basic understanding of 8 bit PIC ASM

Again, did you miss my previous post?  That is the lower byte of the base address of the array X[].
#11
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 18:34:57 (permalink)
0
Again, did you miss my previous post?

yes i did was typing, your just to fast :-)
i will make changes and see what happens
davea
 
edit: thanks 1and0 I see you moved everything into factor very smart...
post edited by davea - 2020/12/04 18:41:32
#12
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/04 22:28:25 (permalink)
0
thanks again 
made all changes works fine...
            // multiplier = X[tp--];
            asm("LSLF _tp, W ");
            asm("ADDLW low(_X) "); // sets or clears carry
            asm("MOVWF FSR1L "); // status not Affected
            
            asm("MOVLW 0 "); // status not Affected
            asm("ADDWFC high(_X),W");
            
            //asm("MOVLW high(_X)");
 
            asm("MOVWF FSR1H ");
            asm("MOVIW [0]FSR1");

fixing the overflows is it that simple ???
davea 
 
edit: never mind that won't work...
 
            // multiplier = X[tp--];
            asm("LSLF _tp, W ");
            asm("ADDLW low(_X) "); // sets or clears carry
            asm("MOVWF FSR1L "); // status not Affected
            
            asm("MOVLW high(_X)"); // status not Affected
            asm("ADDWFC _Val_0,W "); // 1 byte that is always zero

            asm("MOVWF FSR1H ");

should work !!
post edited by davea - 2020/12/04 23:30:22
#13
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/05 07:50:47 (permalink) ☄ Helpfulby davea 2020/12/05 10:23:25
0
No need to waste a byte of data memory, use this:
            // multiplier = X[tp--];
            asm("LSLF    _tp, W  ");
            asm("ADDLW   low(_X) "); // sets or clears carry
            asm("MOVWF   FSR1L   ");

            asm("CLRF    FSR1H   ");
            asm("MOVLW   high(_X)");
            asm("ADDWFC  FSR1H   ");

#14
1and0
Access is Denied
  • Total Posts : 12246
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/06 14:10:40 (permalink)
+1 (1)
Shave one word and one cycle:
            // multiplicand = C[i];
            asm("MOVF _i, W ");                            // asm("lslf    _i,w     ");
            asm("ADDWF _i, W ");                           // asm("addwf   _i,w     ");
            asm("ADDWF _i, W ");                           // delete

Is that disassembly listing generated with the PRO mode?
 
post edited by 1and0 - 2020/12/06 14:11:54
#15
davea
Super Member
  • Total Posts : 642
  • Reward points : 0
  • Joined: 2016/01/28 13:12:13
  • Location: Tampa Bay FL USA
  • Status: offline
Re: Disassembly to ASM the hard way 2020/12/06 22:11:43 (permalink)
0
YES it was.. once again outsmarted by a human
 
edit:
I should have seen that
back in the days with freescale parts
LDHX #table
LDX pointer
a BRA table was 2X pointer  (LSRX)
a JMP table was 3X pointer  (INCX)
post edited by davea - 2020/12/06 22:42:50
#16
Jump to:
© 2021 APG vNext Commercial Version 4.5