View previous topic :: View next topic
|
Author |
Message |
mfjude
New User
Joined: 09 Jan 2006 Posts: 20
|
|
|
|
WHAT WILL BE THE RESULT WHEN I AM MOVING S9(3) COMP-3 TO
S9(3).WHAT ARE THE RULES THAT THIS MOVE WOULD FOLLOW ? |
|
Back to top |
|
|
jon_s_rice
Active User
Joined: 24 Mar 2005 Posts: 102 Location: Douglasville, GA USA
|
|
|
|
S9(3) is a zone signed field. Thlast character contains the last digit and the sign.
+0 hex C0
+1 A
+2 B
+3 C
+4 D
+5 E
+6 F
+7 G
+8 H
+9 I
-0 hex D0
+1 J
+2 K
+3 L
+4 M
+5 N
+6 O
+7 P
+8 Q
+9 R |
|
Back to top |
|
|
senthils
Active User
Joined: 15 Nov 2005 Posts: 117 Location: Chennai, India
|
|
|
|
Any necessary conversion of data from one form of internal representation
to another takes place during the move, along with any specified editing
in, or de-editing implied by, the receiving item.
Ex:
01 A PIC S9(3) COMP-3 VALUE 123.
02 B PIC S9(3).
MOVE A TO B.
Now if we display B the output will be 12L |
|
Back to top |
|
|
ulfnsc
New User
Joined: 15 Jan 2004 Posts: 19 Location: Stockholm, SWEDEN
|
|
|
|
Quote: |
01 A PIC S9(3) COMP-3 VALUE 123.
02 B PIC S9(3).
MOVE A TO B.
|
The output of B will be 123. |
|
Back to top |
|
|
senthils
Active User
Joined: 15 Nov 2005 Posts: 117 Location: Chennai, India
|
|
|
|
the actual value of B will be 123 but B is a signed variable. So as jon_s_rice said the sign will be over-punched on the last digit. So when you try to DISPLAY B the output will be 12L |
|
Back to top |
|
|
wooyoo
New User
Joined: 08 Mar 2006 Posts: 6
|
|
|
|
i have to say i dont understand jon_s_rice 's table , anybody can give a detail explanation? |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi wooyoo,
When a packed field (comp-3) is moved to a DISPLAY format field the assembler instructions generated by the compiler do the following:
The packed field looks like this in memory "nnns", where "n" is any 4 bit digit from 0 to 9 and "s" is either a 4 bit "C" (1100) the sign for a positive value or "D" (1101) the sign for a negative value. If there's no sign in the PIC, the "s" is "F" (1111).
When the move takes place each "n" (except for the last) is expanded to 8 bits by appending a 4 bit "F" (1111) before it, resulting in "FnFn" in the receiving DISPLAY format field.
Now for the last (low order) "n". The low order 4 bit digit of a paced field is handled differently from the other digits. It and the 4 bit sign are "flipped" resulting in "sn" so, the packed data resides in the receiving DISPLAY field as "FnFnFnSn".
For example a packed "123D" (-123) looks like "F1F2D3" after the move, "123C" (+123) looks like "F1F2C3", "123F" (123 - no sign in the PIC) looks like "F1F2F3".
Which brings us to Jon's comments. When the low order digit and the sign are flipped, a minus 3 displays as an "L", a plus 3 as a "C", and so on.
Jon probably copied the 1st set of numbers and forgot to change the sign from + to - and that's what confused you.
Anyway, it's not an easy concept to explain, but once you get the idea it's not that bad.
One other thing:
Because packed fields ALWAYS use the sign position, even if it's not included in the PIC, a pic 9(2) comp-3 will use 3 4 bit digits in memory plus the sign 4 bits, for a total of 2 bytes. It's always best to use an odd
number of 9s in the PIC. It's more efficient. The compiler has to generate more assembler code to handle even 9 PICs.
HTH |
|
Back to top |
|
|
wooyoo
New User
Joined: 08 Mar 2006 Posts: 6
|
|
|
|
Hi ,mmwife
Now i understand ,Thanks for your patience . |
|
Back to top |
|
|
|