link87 0 Posted February 18, 2009 Report Share Posted February 18, 2009 I have produces a very simple for-loop below that shows this problem. I have tried running this in -O0, -O1, and -O2 and all produce the same general problem. The code for the body of the for-loop is appearing outside of the actual "loop" section in the assembled code. Here is the example for-loop: unsigned char i; for(i = 0; i < 10; ++i) { unsigned char a; a = i + 1; } And here is the output with -O1: 144: unsigned char i; 145: for(i = 0; i < 10; ++i) { 0048 6A56 CLRF 0x56, ACCESS 004A 0E0A MOVLW 0xa 004C 6056 CPFSLT 0x56, ACCESS 0054 2A56 INCF 0x56, F, ACCESS 0056 D7F9 BRA 0x4a 146: unsigned char a; 147: a = i + 1; 0050 2856 INCF 0x56, W, ACCESS 0052 6E57 MOVWF 0x57, ACCESS 148: } This is for the PIC18F1320 and here is the output of BoostC/BoostLink for version info and anything else of interest: Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files (x86)\SourceBoost\boostc.pic18.exe" dft.c -W2 -t 18F1320 -O1 BoostC Optimizing C Compiler Version 6.91 (for PIC18 architecture) http://www.sourceboost.com Copyright© 2004-2008 Pavel Baranov Copyright© 2004-2008 David Hobday Single user Lite License (Unregistered) for 0 node(s) Limitations: PIC18 max code size:8192 bytes, max RAM banks:2, Non commercial use only dft.c T:\test_dft\dft.c(157): warning: conversion from 'unsigned char*' to 'void*' success Executing: "C:\Program Files (x86)\SourceBoost\boostlink.pic.exe" "T:\test_dft\dft.obj" -p "test_dft" -t 18F1320 -O1 BoostLink Optimizing Linker Version 6.91 http://www.sourceboost.com Copyright© 2004-2008 Pavel Baranov Copyright© 2004-2008 David Hobday Optimisation level:1 Warning unreferenced functions removed: dft in: T:\test_dft\dft.c Building CASM file Memory Usage Report =================== RAM available:256 bytes, used:93 bytes (36.4%), free:163 bytes (63.6%), Heap size:163 bytes, Heap max single alloc:127 bytes ROM available:8192 bytes, used:502 bytes (6.2%), free:7690 bytes (93.8%) success Loaded T:\test_dft\test_dft.COF. BUILD SUCCEEDED: Wed Feb 18 11:08:45 2009 Quote Link to post Share on other sites
Dave 0 Posted February 18, 2009 Report Share Posted February 18, 2009 link87, Not a bug. Here is the example for-loop: unsigned char i; for(i = 0; i < 10; ++i) { unsigned char a; a = i + 1; } And here is the output with -O1: 144: unsigned char i; 145: for(i = 0; i < 10; ++i) { 0048 6A56 CLRF 0x56, ACCESS 004A 0E0A MOVLW 0xa 004C 6056 CPFSLT 0x56, ACCESS 0054 2A56 INCF 0x56, F, ACCESS 0056 D7F9 BRA 0x4a 146: unsigned char a; 147: a = i + 1; 0050 2856 INCF 0x56, W, ACCESS 0052 6E57 MOVWF 0x57, ACCESS 148: } Keep an eye on th addresses, you will see then that the for loop generates asm either side of the code inside the loop. Regards Dave Quote Link to post Share on other sites
link87 0 Posted February 18, 2009 Author Report Share Posted February 18, 2009 Ahh, when I looked at the program memory view instead of the disassembled view, I see what you mean about the addresses. Sorry about that--still getting used to using a C compiler on the PIC. I will check out the Boost IDE and see if that helps any too. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.