CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to interpret the list file

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
energetic007



Joined: 10 Nov 2013
Posts: 10

View user's profile Send private message

how to interpret the list file
PostPosted: Fri Jan 24, 2014 10:38 am     Reply with quote

How to interpret the list file .............
Guys i am guessing what use the list file could be put to and how it can be helpful in debugging. I know its something like the compiler produces the asm codes for the useful codes only in which some computation is done but i am curious to use it for debugging....
Code:

               ROM used:   147 words (2%)
                           Largest free fragment is 2048
               RAM used:   18 (5%) at main() level
                           18 (5%) worst case
               Stack used: 1 locations (0 in main + 1 for interrupts)
               Stack size: 8

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   059
0003:  NOP
0004:  MOVWF  7F
0005:  SWAPF  03,W
0006:  CLRF   03
0007:  MOVWF  21
0008:  MOVF   0A,W
0009:  MOVWF  20
000A:  CLRF   0A
000B:  MOVF   04,W
000C:  MOVWF  22
000D:  MOVF   77,W
000E:  MOVWF  23
000F:  MOVF   78,W
0010:  MOVWF  24
0011:  MOVF   79,W
0012:  MOVWF  25
0013:  MOVF   7A,W
0014:  MOVWF  26
0015:  BCF    03.7
0016:  BCF    03.5
0017:  MOVLW  8C
0018:  MOVWF  04
0019:  BTFSS  00.0
001A:  GOTO   01D
001B:  BTFSC  0C.0
001C:  GOTO   02E
001D:  MOVF   22,W
001E:  MOVWF  04
001F:  MOVF   23,W
0020:  MOVWF  77
0021:  MOVF   24,W
0022:  MOVWF  78
0023:  MOVF   25,W
0024:  MOVWF  79
0025:  MOVF   26,W
0026:  MOVWF  7A
0027:  MOVF   20,W
0028:  MOVWF  0A
0029:  SWAPF  21,W
002A:  MOVWF  03
002B:  SWAPF  7F,F
002C:  SWAPF  7F,W
002D:  RETFIE
002E:  BCF    0A.3
002F:  BCF    0A.4
0030:  GOTO   031
.................... #INCLUDE <16F877A.H>
.................... //////// Standard Header file for the PIC16F877A device ////////////////
.................... #device PIC16F877A
.................... 
.................... #list
.................... 
.................... #fuses NOWDT,NOPUT,NOLVP,NOCPD
.................... #use delay(clock=4m)
.................... #byte tmr0=0x01
.................... int1 tick;
.................... int16 count=0;
.................... int16 count1=0;
.................... #INT_TIMER1
.................... void isr(void)
.................... {
.................... count++;
0031:  INCF   28,F
0032:  BTFSC  03.2
0033:  INCF   29,F
.................... if(count==5)   
0034:  MOVF   28,W
0035:  SUBLW  05
0036:  BTFSS  03.2
0037:  GOTO   055
0038:  MOVF   29,F
0039:  BTFSS  03.2
003A:  GOTO   055
.................... {
....................  count=0;
003B:  CLRF   29
003C:  CLRF   28
....................  count1++;
003D:  INCF   2A,F
003E:  BTFSC  03.2
003F:  INCF   2B,F
....................  output_toggle(PIN_A5);   
0040:  BSF    03.5
0041:  BCF    05.5
0042:  MOVLW  20
0043:  BCF    03.5
0044:  XORWF  05,F
....................  if(count1==30)
0045:  MOVF   2A,W
0046:  SUBLW  1E
0047:  BTFSS  03.2
0048:  GOTO   055
0049:  MOVF   2B,F
004A:  BTFSS  03.2
004B:  GOTO   055
....................  {
....................  count1=0;
004C:  CLRF   2B
004D:  CLRF   2A
....................  output_toggle(PIN_C3);
004E:  BCF    2C.3
004F:  MOVF   2C,W
0050:  BSF    03.5
0051:  MOVWF  07
0052:  MOVLW  08
0053:  BCF    03.5
0054:  XORWF  07,F
....................  }
.................... }
0055:  BCF    0C.0
0056:  BCF    0A.3
0057:  BCF    0A.4
0058:  GOTO   01D
.................... }
.................... 
.................... void main()
0059:  MOVF   03,W
005A:  ANDLW  1F
005B:  MOVWF  03
005C:  CLRF   29
005D:  CLRF   28
005E:  CLRF   2B
005F:  CLRF   2A
0060:  MOVLW  FF
0061:  MOVWF  2C
0062:  BSF    03.5
0063:  BSF    1F.0
0064:  BSF    1F.1
0065:  BSF    1F.2
0066:  BCF    1F.3
0067:  MOVLW  07
0068:  MOVWF  1C
0069:  BCF    03.7
.................... { 
....................  output_a(0x00);
006A:  CLRF   05
006B:  BCF    03.5
006C:  CLRF   05
....................  output_c(0x00);
006D:  MOVLW  00
006E:  MOVWF  2C
006F:  BSF    03.5
0070:  CLRF   07
0071:  BCF    03.5
0072:  CLRF   07
....................  setup_adc(ADC_OFF);
0073:  BCF    1F.0
....................  setup_comparator(NC_NC_NC_NC);
0074:  MOVLW  07
0075:  BSF    03.5
0076:  MOVWF  1C
0077:  MOVF   05,W
0078:  MOVWF  05
0079:  MOVLW  02
007A:  MOVWF  77
007B:  DECFSZ 77,F
007C:  GOTO   07B
007D:  GOTO   07E
007E:  NOP
007F:  MOVF   1C,W
0080:  BCF    03.5
0081:  BCF    0D.6
....................  setup_psp(PSP_DISABLED);
0082:  BSF    03.5
0083:  BCF    09.4
....................  setup_timer_0(T1_INTERNAL|T1_DIV_BY_4);
0084:  MOVF   01,W
0085:  ANDLW  C0
0086:  IORLW  A5
0087:  MOVWF  01
....................  enable_interrupts (GLOBAL);
0088:  MOVLW  C0
0089:  BCF    03.5
008A:  IORWF  0B,F
....................  enable_interrupts (INT_TIMER1);
008B:  BSF    03.5
008C:  BSF    0C.0
....................  do
....................  { 
....................  output_high(PIN_A3); 
008D:  BCF    05.3
008E:  BCF    03.5
008F:  BSF    05.3
....................   
....................  }
....................  while(1==1);
0090:  BSF    03.5
0091:  GOTO   08D
.................... }
.................... 
0092:  SLEEP
.................... 
.................... 

Configuration Fuses:
   Word  1: 3F7B   RC NOWDT NOPUT BROWNOUT NOLVP NOCPD NOWRT NODEBUG NOPROTECT
C Turner



Joined: 10 Nov 2003
Posts: 40
Location: Utah

View user's profile Send private message

PostPosted: Fri Jan 24, 2014 11:34 am     Reply with quote

The things for which I find the list file to be most useful are:

- Optimizing code produced by the compiler.
- Divining the nature of compiler bugs.

On the first one, consider the following two operations on an unsigned 32 bit integer ("a") on a PIC16 processor in which one may want to align some bits with a piece of hardware or divide the value by two:

a >>= 1;

shift_right(&a, 4, 0);

They both accomplish (more or less) the same thing in that "a" gets shifted to the right one bit and divided-by-two, but if you take a look at the code listing you'll see that they produce slightly different code. In some cases - such as those where space and/or timing is at a premium - knowing what sort of C code produces the smallest, most compact assembly is crucial. (The CCS manual gives some nice examples where some "clever" C code results in very ugly, inefficient assembly.)

Another example would be for a function like "write_eeprom()" - at least in the PIC16F series. If one is writing to the EEPROM in several places throughout the code, it may go unnoticed that the entire function for doing this is repeated every time it is called, taking up quite a bit of space. Knowing that - by having looked at the list file - one could place it in its own, separate function and prevent that from happening!


When I started writing more code PIC code in C than assembly, I looked at the resulting ASM file quite often and experimented to see how the C code affected the efficiency of the resulting code - the result of this is that my PIC C code often looks a bit different from code that I would write on a system from which I was more separated from the hardware.

Another good reason to at least take a look at the list file now and then is that is refreshes the understanding of the PIC's opcodes and hardware structure: Maintaining touch with this aspect of the hardware is very important when writing code for an embedded processor as you really cannot (and should not!) stray too far if you want to write reasonably efficient code on a processor with (usually!) very limited resources.


* * *

The other point - divining compiler bugs. Most of the time, they are really *my* bugs, but on occasion, once the problem has been distilled to its essence (that is, you have written code with the fewest-possible number of lines that clearly demonstrates the issue) being able to step through code of minimal complexity better allows an understanding of the problem.

The most recent example for me was when, in some early versions of the 5.x compiler, simply using "sprintf" caused the interrupts to be turned off. The problem, isolated in a simple example, was passed to the CCS folks and fixed in the very next release.

* * *

Another thing that is not always appreciated is demonstrated in your example: Even code that might seem to do nothing on the first examination (e.g. compiler directives) can cause surprising amount of code to be generated - say, to zero at the RAM, set up hardware, etc. and if space is at a premium, a close examination of the list file might well reveal unnecessary "goings on" that, in a specific case, could be safely omitted.

I'm sure that there are many more instances/examples, but the above two are those that come to mind first.

CT
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 24, 2014 12:00 pm     Reply with quote

The first thing to look at is your fuses. Instantaneous recognition of a bug:
Quote:
Configuration Fuses:
Word 1: 3F7B RC NOWDT NOPUT BROWNOUT NOLVP NOCPD NOWRT NODEBUG NOPROTECT

The compiler defaults to the RC fuse when you don't specify an oscillator
fuse. The RC fuse is a primitive hobbyist-type oscillator, left over from
the early days of the PIC, consisting of an external Resistor-capacitor
circuit.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group