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 CCS Technical Support

Division Problem. a/b over number division like 10/5

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



Joined: 22 Feb 2006
Posts: 14

View user's profile Send private message

Division Problem. a/b over number division like 10/5
PostPosted: Mon Mar 13, 2006 8:20 pm     Reply with quote

When I divide two numbers using integer variables, PICC assembly code jumps to start of the code.

int a;
int b;
int c;

a=10;
b=5;
c=a/c;

while when I am dividing by two numbers I dont have any problems.

c=10/5

Why is the great difference?

Source Codes:

#include "C:\Documents and Settings\Parthipan\Desktop\PICC\division.h"

void main()
{
int a;
int b;
int c;
int d;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

a=10;
b=5;
c=10/5;
d=a/b;
}

*****************************************************
CCS PCM C Compiler, Version 3.242, 16465 13-Nov-01 07:49

Filename: C:\Documents and Settings\Parthipan\Desktop\PICC\division.lst

ROM used: 48 words (5%)
Largest free fragment is 976
RAM used: 6 (9%) at main() level
9 (13%) worst case
Stack: 1 locations

*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 019
0003: NOP
.................... #include "C:\Documents and Settings\Parthipan\Desktop\PICC\division.h"
.................... #include <16F84.h>
.................... //////// Standard Header file for the PIC16F84 device ////////////////
.................... #device PIC16F84
.................... #list
....................
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES HS //High speed Osc (> 4mhz)
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES NOPROTECT //Code not protected from reading
....................
.................... #use delay(clock=20000000)
....................
....................
....................
.................... void main()
.................... {
0019: CLRF 04
001A: MOVLW 1F
001B: ANDWF 03,F
.................... int a;
.................... int b;
.................... int c;
.................... int d;
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
001C: BSF 03.5
001D: MOVF 01,W
001E: ANDLW C7
001F: IORLW 08
0020: MOVWF 01
....................
.................... a=10;
0021: MOVLW 0A
0022: BCF 03.5
0023: MOVWF 0F
.................... b=5;
0024: MOVLW 05
0025: MOVWF 10
.................... c=10/5;
0026: MOVLW 02
0027: MOVWF 11
.................... d=a/b;
0028: MOVF 0F,W
0029: MOVWF 13
002A: MOVF 10,W
002B: MOVWF 14
002C: GOTO 004 ****-----------> My problem is here!!!!!!!!
002D: MOVF 0D,W
002E: MOVWF 12
.................... }
002F: SLEEP

Configuration Fuses:
Word 1: 3FFA HS NOWDT NOPUT NOPROTECT


Please help me!
[/code][/list]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 8:40 pm     Reply with quote

Quote:
When I divide two numbers using integer variables, PICC assembly code jumps to start of the code.

I think you have a problem in understanding what the compiler is doing,
and not an actual problem.


Quote:

while when I am dividing by two numbers I dont have any problems.
c=10/5


With the code above, the compiler will do the division at compile time.
Your PC does the division. The compiler then creates ASM code to
load the result (a constant) into "c".


Quote:
d=a/b;
}

002C: GOTO 004 ****-----------> My problem is here!!!!!!!!
002D: MOVF 0D,W

There is no problem. The code is jumping to the CCS library code
which does the division operation. Because the two operands are
variables, the result must be calculated at runtime and this requires
the PIC to execute the library code.
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