Instruction Cycle Calculation Of C Code !

Author
Dhivakar RS
Super Member
  • Total Posts : 213
  • Reward points : 0
  • Joined: 2016/10/15 03:44:54
  • Location: Coimbatore
  • Status: offline
2017/12/07 05:56:10 (permalink)
0

Instruction Cycle Calculation Of C Code !

Hai guys.  I want to know how much time my code take to execute my program. Suppose i write a simple code for led blinking in MPLAB IDE & HTC Compiler for PIC16F877A using 4 MHz. So, Execution Time for One Instruction is 1us.
 

 
#include<htc.h>
 
#define _XTAL_FREQ 4e6
 
__CONFIG(0x3F3A);
 
void main()
 
{
 
PORTD=0x00;
 
TRISD=0x00;
 
while(1)
 
{
 
RD0=1;
 
__delay_ms(500);
 
RD0=0;
 
__delay_ms(500);
 
}
 
}
 

 
 
From the above c code consists 16 lines of code apart from square brackets, delay function it consists 9 lines of code.
 
That means shall i take it as 9 instructions????! am i right????
 
what i want to know is how much instruction this program consists of? My intention is i should say how many instructions is written by just seeing c code.
#1

12 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 1147
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/07 06:18:09 (permalink)
    +1 (1)
    Not really possible. You need to look at the disassembly view or listing file to determine that. With a very small simple program you might be able to guess reasonably well, but as the code gets bigger and more complex it's not worth the effort. Compiling the code tells you how big it is.

    Oh well - there's always next year
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 16647
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/07 08:07:50 (permalink)
    0
    That is not likely to be 9 instruction. But some C statements are one to one will an an opcode. However most are not.
    #3
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/07 15:02:28 (permalink)
    +2 (2)
    dhivakarrs
    That means shall i take it as 9 instructions????! am i right????

    No. Completely wrong.
    You're not allowing for bank selecting instructions required by POIC1F architecture, etc.
    As others suggested, you need to examine the compiled code to get an idea of how it does it.
    Look in the .LST file in your project folder.
    It also makes a HUGE difference if you are using the compiler in FREE mode or PRO mode.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #4
    Dhivakar RS
    Super Member
    • Total Posts : 213
    • Reward points : 0
    • Joined: 2016/10/15 03:44:54
    • Location: Coimbatore
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 01:52:58 (permalink)
    0
    Ok guys! Thank u for the suggestions mbrowning, Nkurzman and qub.
    #5
    Dhivakar RS
    Super Member
    • Total Posts : 213
    • Reward points : 0
    • Joined: 2016/10/15 03:44:54
    • Location: Coimbatore
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 03:02:34 (permalink)
    0
    while opening lst file in project folder i get like this..



    HI-TECH Software PIC Macro Assembler V9.80 build 6745
                                                                                                               Sat Dec 09 15:29:56 2017


         1                           
         2                               ; HI-TECH C Compiler for PIC10/12/16 MCUs V9.80
         3                               ; Copyright (C) 1984-2010 HI-TECH Software
         4                           
         5                               ; Auto-generated runtime startup code for final link stage.
         6                           
         7                               ;
         8                               ; Compiler options:
         9                               ;
        10                               ; -otest.cof -mtest.map --summary=default --output=default main.p1 \
        11                               ; --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g \
        12                               ; --asmlist --errformat=Error   [%n] %f; %l.%c %s \
        13                               ; --msgformat=Advisory[%n] %s --warnformat=Warning [%n] %f; %l.%c %s
        14                               ;
        15                           
        16                           
        17                               processor    16F877A
        18                           
        19                               global    _main,start,_exit,reset_vec
        20                               fnroot    _main
        21                               psect    config,class=CONFIG,delta=2
        22                               psect    idloc,class=IDLOC,delta=2
        23                               psect    code,class=CODE,delta=2
        24                               psect    powerup,class=CODE,delta=2
        25                               psect    reset_vec,class=CODE,delta=2
        26                               psect    maintext,class=CODE,delta=2
        27  0000                         C    set    0
        28  0002                         Z    set    2
        29  0002                         PCL    set    2
        30  0000                         INDF    set    0
        31                           
        32  0003                         STATUS    equ    3
        33  000A                         PCLATH    equ    0Ah
        34                           
        35                               psect    eeprom_data,class=EEDATA,delta=2,space=2
        36                               psect    intentry,class=CODE,delta=2
        37                               psect    functab,class=CODE,delta=2
        38                               global    intlevel0,intlevel1,intlevel2, intlevel3, intlevel4, intlevel5
        39  0000                     intlevel0:
        40  0000                     intlevel1:
        41  0000                     intlevel2:
        42  0000                     intlevel3:
        43  0000                     intlevel4:
        44  0000                     intlevel5:
        45                               psect    init,class=CODE,delta=2
        46                               psect    cinit,class=CODE,delta=2
        47                               psect    text,class=CODE,delta=2
        48                               psect    end_init,class=CODE,delta=2
        49                               psect    clrtext,class=CODE,delta=2
        50  0004                         FSR    set    4
        51                               psect    strings,class=CODE,delta=2,reloc=256
        52                           
        53                               psect    reset_vec
        54  0000                     reset_vec:
        55                               ; No powerup routine
        56                               ; No interrupt routine
        57                           
        58                           
        59                               psect    init
        60  0000                     start
        61  0000                     _exit
        62                               psect    end_init
        63                               global start_initialization
        64  0000  120A  118A  2FD2       ljmp start_initialization    ;jump to C runtime clear & initialization


    HI-TECH Software PICC Macro Assembler V9.80 build 6745
    Symbol Table                                                                                               Sat Dec 09 15:29:56 2017

                   _main 07D6                 _exit 0000                 start 0000  start_initialization 07D2  
               intlevel0 0000             intlevel1 0000             intlevel2 0000             intlevel3 0000  
               intlevel4 0000             intlevel5 0000             reset_vec 0000  

     
     
    Here, How many instructions are present? How to identify those instructions?
    #6
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 03:09:25 (permalink)
    0
    There is only one instruction in that file.
    You're using an old version of HiTech C. I think that one produces multiple LST files.
    Later versions, and all versions of XC8, put it all into one LST file.
     
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #7
    Dhivakar RS
    Super Member
    • Total Posts : 213
    • Reward points : 0
    • Joined: 2016/10/15 03:44:54
    • Location: Coimbatore
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 04:05:02 (permalink)
    0
    Yeah Ok. Now i have built one example code of Blinking Led using PIC18F4550 in MPLAB XIDE with XC8 Compiler.
     
    Source Code

    /*
     Led blinking using PIC18F4550
     */

    #include "osc_config.h"  /*Header file for Configuration Bits*/
    #include <pic18f4550.h>  /*Header file PIC18f4550 definitions*/

    #define LED LATB
    void MSdelay(unsigned int);

    void main()
    {
        OSCCON=0x72;        /* Use internal oscillator of 8MHz Frequency */
        TRISB=0x00;         /* Set direction of PORTB as OUTPUT to which LED is connected */
        while(1)
        {
            LED = 0xff;     /* Turn ON LED for 500 ms */
            MSdelay (500);
            LED = 0;        /* Turn OFF LED for 500 ms */
            MSdelay (500);
        }
    }
    void MSdelay(unsigned int val)
    {
     unsigned int i,j;
     for(i=0;i<val;i++)
         for(j=0;j<165;j++);  /*This count Provide delay of 1 ms for 8MHz Frequency */
     }

     
     
    Lst file of this code



    Microchip Technology PIC18 LITE Macro Assembler V1.40 build -251452761
                                                                                                   Wed Oct 04 16:06:58 2017

    Microchip Technology Omniscient Code Generator v1.40 (Free mode) build 201612010151
         1                               processor    18F4550
         2                               fnconf    rparam,??,?,0
         3                               opt    pw 120
         4                               opt    lm
         5                               psect    cinit,global,reloc=2,class=CODE,delta=1
         6                               psect    cstackCOMRAM,global,class=COMRAM,space=1,delta=1,noexec
         7                               psect    text0,global,reloc=2,class=CODE,delta=1
         8                               psect    text1,global,reloc=2,class=CODE,delta=1
         9                               psect    intsave_regs,global,class=BIGRAM,space=1,delta=1,noexec
        10                               psect    rparam,global,class=COMRAM,space=1,delta=1,noexec
        11  0000                     
        12                           ; Version 1.40
        13                           ; Generated 01/12/2016 GMT
        14                           ;
        15                           ; Copyright © 2016, Microchip Technology Inc. and its subsidiaries ("Microchip")
        16                           ; All rights reserved.
        17                           ;
        18                           ; This software is developed by Microchip Technology Inc. and its subsidiaries ("Microch
          +                          ip").
        19                           ;
        20                           ; Redistribution and use in source and binary forms, with or without modification, are
        21                           ; permitted provided that the following conditions are met:
        22                           ;
        23                           ;     1. Redistributions of source code must retain the above copyright notice, this lis
          +                          t of
        24                           ;        conditions and the following disclaimer.
        25                           ;
        26                           ;     2. Redistributions in binary form must reproduce the above copyright notice, this
          +                          list
        27                           ;        of conditions and the following disclaimer in the documentation and/or other
        28                           ;        materials provided with the distribution.
        29                           ;
        30                           ;     3. Microchip's name may not be used to endorse or promote products derived from th
          +                          is
        31                           ;        software without specific prior written permission.
        32                           ;
        33                           ; THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
        34                           ; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS F
          +                          OR
        35                           ; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY DIRECT, INDIREC
          +                          T,
        36                           ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
        37                           ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS
        38                           ; INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ST
          +                          RICT
        39                           ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U
          +                          SE OF
        40                           ; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        41                           ;
        42                           ;
        43                           ; Code-generator required, PIC18F4550 Definitions
        44                           ;
        45                           ; SFR Addresses
        46  0000                     _LATB    set    3978
        47  0000                     _OSCCON    set    4051
        48  0000                     _TRISB    set    3987
        49                           
        50                           ; #config settings
        51  0000                     
        52                               psect    cinit
        53  007F9C                     __pcinit:
        54                               opt stack 0
        55  007F9C                     start_initialization:
        56                               opt stack 0
        57  007F9C                     __initialization:
        58                               opt stack 0
        59  007F9C                     end_of_initialization:
        60                               opt stack 0
        61  007F9C                     __end_of__initialization:
        62                               opt stack 0
        63  007F9C  0100                   movlb    0
        64  007F9E  EFD1  F03F             goto    _main    ;jump to C main() function
        65                           
        66                               psect    cstackCOMRAM
        67  000001                     __pcstackCOMRAM:
        68                               opt stack 0
        69  000001                     MSdelay@val:
        70                               opt stack 0
        71                           
        72                           ; 2 bytes @ 0x0
        73  000001                         ds    2
        74  000003                     MSdelay@i:
        75                               opt stack 0
        76                           
        77                           ; 2 bytes @ 0x2
        78  000003                         ds    2
        79  000005                     MSdelay@j:
        80                               opt stack 0
        81                           
        82                           ; 2 bytes @ 0x4
        83  000005                         ds    2
        84  000007                     
        85                           ; 1 bytes @ 0x6
        86 ;;
        87 ;;Main: autosize = 0, tempsize = 0, incstack = 0, save=0
        88 ;;
        89 ;; *************** function _main *****************
        90 ;; Defined at:
        91 ;;        line 12 in file "blink_of_led.c"
        92 ;; Parameters:    Size  Location     Type
        93 ;;        None
        94 ;; Auto vars:     Size  Location     Type
        95 ;;        None
        96 ;; Return value:  Size  Location     Type
        97 ;;                  1    wreg      void
        98 ;; Registers used:
        99 ;;        wreg, status,2, status,0, cstack
       100 ;; Tracked objects:
       101 ;;        On entry : 0/0
       102 ;;        On exit  : 0/0
       103 ;;        Unchanged: 0/0
       104 ;; Data sizes:     COMRAM   BANK0   BANK1   BANK2   BANK3   BANK4   BANK5   BANK6   BANK7
       105 ;;      Params:         0       0       0       0       0       0       0       0       0
       106 ;;      Locals:         0       0       0       0       0       0       0       0       0
       107 ;;      Temps:          0       0       0       0       0       0       0       0       0
       108 ;;      Totals:         0       0       0       0       0       0       0       0       0
       109 ;;Total ram usage:        0 bytes
       110 ;; Hardware stack levels required when called:    1
       111 ;; This function calls:
       112 ;;        _MSdelay
       113 ;; This function is called by:
       114 ;;        Startup code after reset
       115 ;; This function uses a non-reentrant model
       116 ;;
       117                           
       118                               psect    text0
       119  007FA2                     __ptext0:
       120                               opt stack 0
       121  007FA2                     _main:
       122                               opt stack 30
       123                           
       124                           ;blink_of_led.c: 14: OSCCON=0x72;
       125                           
       126                           ;incstack = 0
       127  007FA2  0E72                   movlw    114
       128  007FA4  6ED3                   movwf    4051,c    ;volatile
       129                           
       130                           ;blink_of_led.c: 15: TRISB=0x00;
       131  007FA6  0E00                   movlw    0
       132  007FA8  6E93                   movwf    3987,c    ;volatile
       133  007FAA                     l662:
       134                           
       135                           ;blink_of_led.c: 17: {
       136                           ;blink_of_led.c: 18: LATB = 0xff;
       137  007FAA  688A                   setf    3978,c    ;volatile
       138                           
       139                           ;blink_of_led.c: 19: MSdelay (500);
       140  007FAC  0E01                   movlw    1
       141  007FAE  6E02                   movwf    MSdelay@val+1,c
       142  007FB0  0EF4                   movlw    244
       143  007FB2  6E01                   movwf    MSdelay@val,c
       144  007FB4  ECE5  F03F             call    _MSdelay    ;wreg free
       145                           
       146                           ;blink_of_led.c: 20: LATB = 0;
       147  007FB8  0E00                   movlw    0
       148  007FBA  6E8A                   movwf    3978,c    ;volatile
       149                           
       150                           ;blink_of_led.c: 21: MSdelay (500);
       151  007FBC  0E01                   movlw    1
       152  007FBE  6E02                   movwf    MSdelay@val+1,c
       153  007FC0  0EF4                   movlw    244
       154  007FC2  6E01                   movwf    MSdelay@val,c
       155  007FC4  ECE5  F03F             call    _MSdelay    ;wreg free
       156  007FC8  D7F0                   goto    l662
       157  007FCA                     __end_of_main:
       158                               opt stack 0
       159                           
       160 ;; *************** function _MSdelay *****************
       161 ;; Defined at:
       162 ;;        line 24 in file "blink_of_led.c"
       163 ;; Parameters:    Size  Location     Type
       164 ;;  val             2    0[COMRAM] unsigned int
       165 ;; Auto vars:     Size  Location     Type
       166 ;;  j               2    4[COMRAM] unsigned int
       167 ;;  i               2    2[COMRAM] unsigned int
       168 ;; Return value:  Size  Location     Type
       169 ;;                  1    wreg      void
       170 ;; Registers used:
       171 ;;        wreg, status,2, status,0
       172 ;; Tracked objects:
       173 ;;        On entry : 0/0
       174 ;;        On exit  : 0/0
       175 ;;        Unchanged: 0/0
       176 ;; Data sizes:     COMRAM   BANK0   BANK1   BANK2   BANK3   BANK4   BANK5   BANK6   BANK7
       177 ;;      Params:         2       0       0       0       0       0       0       0       0
       178 ;;      Locals:         4       0       0       0       0       0       0       0       0
       179 ;;      Temps:          0       0       0       0       0       0       0       0       0
       180 ;;      Totals:         6       0       0       0       0       0       0       0       0
       181 ;;Total ram usage:        6 bytes
       182 ;; Hardware stack levels used:    1
       183 ;; This function calls:
       184 ;;        Nothing
       185 ;; This function is called by:
       186 ;;        _main
       187 ;; This function uses a non-reentrant model
       188 ;;
       189                           
       190                               psect    text1
       191  007FCA                     __ptext1:
       192                               opt stack 0
       193  007FCA                     _MSdelay:
       194                               opt stack 30
       195                           
       196                           ;blink_of_led.c: 26: unsigned int i,j;
       197                           ;blink_of_led.c: 27: for(i=0;i<val;i++)
       198                           
       199                           ;incstack = 0
       200  007FCA  0E00                   movlw    0
       201  007FCC  6E04                   movwf    MSdelay@i+1,c
       202  007FCE  0E00                   movlw    0
       203  007FD0  6E03                   movwf    MSdelay@i,c
       204  007FD2  D00F                   goto    l658
       205  007FD4                     l646:
       206                           
       207                           ;blink_of_led.c: 28: for(j=0;j<165;j++);
       208  007FD4  0E00                   movlw    0
       209  007FD6  6E06                   movwf    MSdelay@j+1,c
       210  007FD8  0E00                   movlw    0
       211  007FDA  6E05                   movwf    MSdelay@j,c
       212  007FDC                     l648:
       213  007FDC  5006                   movf    MSdelay@j+1,w,c
       214  007FDE  E107                   bnz    l656
       215  007FE0  0EA5                   movlw    165
       216  007FE2  5C05                   subwf    MSdelay@j,w,c
       217  007FE4  B0D8                   btfsc    status,0,c
       218  007FE6  D003                   goto    l656
       219  007FE8  4A05                   infsnz    MSdelay@j,f,c
       220  007FEA  2A06                   incf    MSdelay@j+1,f,c
       221  007FEC  D7F7                   goto    l648
       222  007FEE                     l656:
       223  007FEE  4A03                   infsnz    MSdelay@i,f,c
       224  007FF0  2A04                   incf    MSdelay@i+1,f,c
       225  007FF2                     l658:
       226  007FF2  5001                   movf    MSdelay@val,w,c
       227  007FF4  5C03                   subwf    MSdelay@i,w,c
       228  007FF6  5002                   movf    MSdelay@val+1,w,c
       229  007FF8  5804                   subwfb    MSdelay@i+1,w,c
       230  007FFA  B0D8                   btfsc    status,0,c
       231  007FFC  0012                   return    
       232  007FFE  D7EA                   goto    l646
       233  008000                     __end_of_MSdelay:
       234                               opt stack 0
       235  0000                     status    equ    0xFD8
       236                           status    equ    0xFD8
       237                           
       238                               psect    rparam
       239  0000                     status    equ    0xFD8


    Data Sizes:
        Strings     0
        Constant    0
        Data        0
        BSS         0
        Persistent  0
        Stack       0

    Auto Spaces:
        Space          Size  Autos    Used
        COMRAM           95      6       6
        BANK0           160      0       0
        BANK1           256      0       0
        BANK2           256      0       0
        BANK3           256      0       0
        BANK4           256      0       0
        BANK5           256      0       0
        BANK6           256      0       0
        BANK7           256      0       0

    Pointer List with Targets:

        None.

    Critical Paths under _main in COMRAM

        _main->_MSdelay

    Critical Paths under _main in BANK0

        None.

    Critical Paths under _main in BANK1

        None.

    Critical Paths under _main in BANK2

        None.

    Critical Paths under _main in BANK3

        None.

    Critical Paths under _main in BANK4

        None.

    Critical Paths under _main in BANK5

        None.

    Critical Paths under _main in BANK6

        None.

    Critical Paths under _main in BANK7

        None.

    Call Graph Tables:

     ---------------------------------------------------------------------------------
     (Depth) Function               Calls       Base Space   Used Autos Params    Refs
     ---------------------------------------------------------------------------------
     (0) _main                                                 0     0      0     178
                                _MSdelay
     ---------------------------------------------------------------------------------
     (1) _MSdelay                                              6     4      2     178
                                                  0 COMRAM     6     4      2
     ---------------------------------------------------------------------------------
     Estimated maximum stack depth 1
     ---------------------------------------------------------------------------------

     Call Graph Graphs:

     _main (ROOT)
       _MSdelay

     Address spaces:
    Name               Size   Autos  Total    Cost      Usage
    BITCOMRAM           5F      0       0       0        0.0%
    EEDATA             100      0       0       0        0.0%
    NULL                 0      0       0       0        0.0%
    CODE                 0      0       0       0        0.0%
    COMRAM              5F      6       6       1        6.3%
    STACK                0      0       0       2        0.0%
    DATA                 0      0       0       3        0.0%
    BITBANK0            A0      0       0       4        0.0%
    BANK0               A0      0       0       5        0.0%
    BITBANK1           100      0       0       6        0.0%
    BANK1              100      0       0       7        0.0%
    BITBANK2           100      0       0       8        0.0%
    BANK2              100      0       0       9        0.0%
    BITBANK3           100      0       0      10        0.0%
    BANK3              100      0       0      11        0.0%
    BITBANK4           100      0       0      12        0.0%
    BANK4              100      0       0      13        0.0%
    BITBANK5           100      0       0      14        0.0%
    BANK5              100      0       0      15        0.0%
    BITBANK6           100      0       0      16        0.0%
    BANK6              100      0       0      17        0.0%
    BITBANK7           100      0       0      18        0.0%
    BANK7              100      0       0      19        0.0%
    ABS                  0      0       0      20        0.0%
    BIGRAM             7FF      0       0      21        0.0%
    BITSFR               0      0       0     200        0.0%
    SFR                  0      0       0     200        0.0%


    Microchip Technology PIC18 Macro Assembler V1.40 build -251452761
    Symbol Table                                                                                   Wed Oct 04 16:06:58 2017

                __CFG_BOR$ON 000000              __CFG_BORV$3 000000             __CFG_CP0$OFF 000000  
               __CFG_CP1$OFF 000000             __CFG_CP2$OFF 000000             __CFG_CP3$OFF 000000  
                        l646 7FD4                      l662 7FAA                      l656 7FEE  
                        l648 7FDC                      l658 7FF2             __CFG_CPB$OFF 000000  
               __CFG_CPD$OFF 000000             __CFG_LVP$OFF 000000             __CFG_WDT$OFF 000000  
                       _LATB 000F8A                     _main 7FA2                     start 0000  
            __end_of_MSdelay 8000            __CFG_IESO$OFF 000000             ___param_bank 000000  
             __CFG_CCP2MX$ON 000000                    ?_main 0001                    _TRISB 000F93  
              __CFG_PWRT$OFF 000000            __CFG_WRT0$OFF 000000            __CFG_WRT1$OFF 000000  
              __CFG_WRT2$OFF 000000            __CFG_WRT3$OFF 000000           __CFG_EBTR0$OFF 000000  
             __CFG_FCMEN$OFF 000000           __CFG_EBTR1$OFF 000000           __CFG_EBTR2$OFF 000000  
             __CFG_EBTR3$OFF 000000            __CFG_WRTB$OFF 000000            __CFG_WRTC$OFF 000000  
              __CFG_WRTD$OFF 000000           __CFG_EBTRB$OFF 000000                    status 000FD8  
             __CFG_ICPRT$OFF 000000           __CFG_MCLRE$OFF 000000          __initialization 7F9C  
               __end_of_main 7FCA                   ??_main 0007            __activetblptr 000000  
                  ??_MSdelay 0003                   _OSCCON 000FD3           __CFG_XINST$OFF 000000  
             __CFG_STVREN$ON 000000               __accesstop 0060  __end_of__initialization 7F9C  
            __CFG_PBADEN$OFF 000000            ___rparam_used 000001           __pcstackCOMRAM 0001  
                    _MSdelay 7FCA          __CFG_VREGEN$OFF 000000                  __Hparam 0000  
                    __Lparam 0000                  __pcinit 7F9C                  __ramtop 0800  
                    __ptext0 7FA2                  __ptext1 7FCA     end_of_initialization 7F9C  
        start_initialization 7F9C         __CFG_LPT1OSC$OFF 000000                 ?_MSdelay 0001  
                   MSdelay@i 0003                 MSdelay@j 0005         __CFG_WDTPS$32768 000000  
           __size_of_MSdelay 0036                 __Hrparam 0000                 __Lrparam 0000  
              __size_of_main 0028               MSdelay@val 0001      __CFG_FOSC$INTOSC_EC 000000  

     
    As i already mentioned .......
    Here, How many instructions are present?
    How to identify those instructions?
    #8
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 04:13:27 (permalink)
    +2 (2)
    Here is your main() function
      124                           ;blink_of_led.c: 14: OSCCON=0x72;
       125                           
       126                           ;incstack = 0
       127  007FA2  0E72                   movlw    114
       128  007FA4  6ED3                   movwf    4051,c    ;volatile
       129                           
       130                           ;blink_of_led.c: 15: TRISB=0x00;
       131  007FA6  0E00                   movlw    0
       132  007FA8  6E93                   movwf    3987,c    ;volatile
       133  007FAA                     l662:
       134                           
       135                           ;blink_of_led.c: 17: {
       136                           ;blink_of_led.c: 18: LATB = 0xff;
       137  007FAA  688A                   setf    3978,c    ;volatile
       138                           
       139                           ;blink_of_led.c: 19: MSdelay (500);
       140  007FAC  0E01                   movlw    1
       141  007FAE  6E02                   movwf    MSdelay@val+1,c
       142  007FB0  0EF4                   movlw    244
       143  007FB2  6E01                   movwf    MSdelay@val,c
       144  007FB4  ECE5  F03F             call    _MSdelay    ;wreg free
       145                           
       146                           ;blink_of_led.c: 20: LATB = 0;
       147  007FB8  0E00                   movlw    0
       148  007FBA  6E8A                   movwf    3978,c    ;volatile
       149                           
       150                           ;blink_of_led.c: 21: MSdelay (500);
       151  007FBC  0E01                   movlw    1
       152  007FBE  6E02                   movwf    MSdelay@val+1,c
       153  007FC0  0EF4                   movlw    244
       154  007FC2  6E01                   movwf    MSdelay@val,c
       155  007FC4  ECE5  F03F             call    _MSdelay    ;wreg free
       156  007FC8  D7F0                   goto    l662
       157  007FCA                     __end_of_main:

    The first column is just a line number.
    The second column is the address in PIC code memory.
    The third column is the instruction.
    That is then followed by disassembly of the instruction.
    The original C code is shown as a comment just before each group of instructions.
    So:
       127  007FA2  0E72                   movlw    114

    This is line#127, at address 7FA2 is the instruction 0x0E72, which is a "MOVLW 114".
    114 = 0x72. Is is preparing to write that value to OSCCON in the next instruction.
     
    Of course you need to understand PIC16 assembly code to understand all this.
     
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #9
    Dhivakar RS
    Super Member
    • Total Posts : 213
    • Reward points : 0
    • Joined: 2016/10/15 03:44:54
    • Location: Coimbatore
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 05:00:29 (permalink)
    0
    Great Explanation sir!
    So, at the least case i get minimum of two instructions for a c code.
    Yes, need to understand Assembly code.
    post edited by Dhivakar RS - 2017/12/09 05:05:02
    #10
    Dhivakar RS
    Super Member
    • Total Posts : 213
    • Reward points : 0
    • Joined: 2016/10/15 03:44:54
    • Location: Coimbatore
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 05:16:17 (permalink)
    0
    I have two doubts, i don't want to create another thread.
     
    Doubt No:1
    What is the difference between __delay_ms() , Timer delay and Loop running delay ?????
    Which one is ideal for programming....?
    __delay_ms() is like Loop running delay????? Will this affect CPU speed unlike Timer.
     
    Doubt No:2
    How to create Loop Running Delay based on Fosc?
    Though the above code i copied for programming. I understand everything.. Except the delay running for loop..

     
     
     
    void MSdelay(unsigned int val)
    {
     unsigned int i,j;
     for(i=0;i<val;i++)
         for(j=0;j<165;j++);  /*This count Provide delay of 1 ms for 8MHz Frequency */
     }
     
     
     

     
    How to create like this?
    How they found specifically 165 for the second for loop????
    post edited by Dhivakar RS - 2017/12/09 05:18:25
    #11
    mbrowning
    Just a Member
    • Total Posts : 1147
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 06:55:34 (permalink)
    0
    For precise timing, a loop like that has to be hand tuned either experimentally or by inspecting the dissassembly. And the actual delay will change maybe a bit from compile to compile, or with a new compiler version. This is why XC8 provides the __delay_ms() , _us() functions to create a consistent delay over new versions or changes in code.
     
    I personally never use the __delay_ms() function except maybe occasionally during startup because (like the loop above) the PIC can do nothing else while it's running the loop. I will always use a 100us or 1ms timer interrupt to make delays beyond a few us.

    Oh well - there's always next year
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2765
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Instruction Cycle Calculation Of C Code ! 2017/12/09 12:09:02 (permalink)
    0
    LED = 0xff;     /* Turn ON LED for 500 ms */
    That will cause you problems later on because you are setting 8bits rather than one bit.
    post edited by Gort2015 - 2017/12/09 14:57:22

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Jump to:
    © 2018 APG vNext Commercial Version 4.5