View previous topic :: View next topic |
Author |
Message |
roccat
Joined: 13 Jan 2013 Posts: 8
|
multiplication problem |
Posted: Sun Jun 09, 2013 9:09 am |
|
|
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
|
|
Posted: Sun Jun 09, 2013 9:21 am |
|
|
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
|
|
Posted: Sun Jun 09, 2013 9:42 am |
|
|
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
|
|
Posted: Sun Jun 09, 2013 9:42 am |
|
|
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
|
|
Posted: Sun Jun 09, 2013 9:48 am |
|
|
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
|
|
Posted: Sun Jun 09, 2013 11:50 pm |
|
|
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. |
|
|
|