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

multiplication problem

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



Joined: 13 Jan 2013
Posts: 8

View user's profile Send private message

multiplication problem
PostPosted: Sun Jun 09, 2013 9:09 am     Reply with quote

Hello. I'm using 5.005 demo. dspic33ep64gp504

Code:
char a,b;
a=1;
b=a*3;


After multiplying b = 6, and should be 3. Why is that?

asm list:
Code:

231:               a=1;
  0806  B3C010     mov.b #0x1,0x0000
  0808  B7F048     mov.b 0x0000,0x1048
232:               b=a*3;
  080A  BFD048     mov.b 0x1048,0x0000
  080C  FB0000     se 0x0000,0x0000
  080E  780200     mov.w 0x0000,0x0008
  0810  B82063     mul.uu 0x0008,#3,0x0000
  0812  B7F047     mov.b 0x0000,0x1047
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 09, 2013 9:21 am     Reply with quote

try this

Code:
int a,b;
a =  1;
b = a * 3;


change data type to int

Good Luck,
z3ngew
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jun 09, 2013 9:42 am     Reply with quote

Where do you see the result of 6? The result of the shown assembly code will be 3.
roccat



Joined: 13 Jan 2013
Posts: 8

View user's profile Send private message

PostPosted: Sun Jun 09, 2013 9:42 am     Reply with quote

It did not help. Anyway 6.
If a = 2, after multiplication b=12.

Code:
231:                a =  2;
  079C  200024     mov.w #0x2,0x0008
  079E  888544     mov.w 0x0008,0x10a8
232:                b = a * 3;
  07A0  808544     mov.w 0x10a8,0x0008
  07A2  B82063     mul.uu 0x0008,#3,0x0000
  07A4  888550     mov.w 0x0000,0x10aa
roccat



Joined: 13 Jan 2013
Posts: 8

View user's profile Send private message

PostPosted: Sun Jun 09, 2013 9:48 am     Reply with quote

FvM wrote:
Where do you see the result of 6? The result of the shown assembly code will be 3.


mplab -> mplab sim -> watch.

I checked on pic16f913, the result was 3. on this chip result 6.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jun 09, 2013 11:50 pm     Reply with quote

The strange result can be traced down to
Code:
0220  B82063     mul.uu 0x0008,#3,0x0000

Apparently a MPLAB SIM bug. The same instruction is shown with correct result for other 16-Bit PICs.
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