View previous topic :: View next topic
|
Author |
Message |
mijanurit Currently Banned New User
Joined: 26 Aug 2005 Posts: 33 Location: bangalore
|
|
|
|
hi davidatk,
plz tell me in details for the following ...
Quote:
01 filler
05 x pic x(5).
05 y redefines x pic 9(5).
when x=123 3
what is the content of y?
in case of x=123 z OR x='123=3' what will be the content of y if y is declared as pic s9(5)?
thanks and regards
mijanurit |
|
Back to top |
|
|
gowtham_1982 Warnings : 1 Active User
Joined: 02 Dec 2005 Posts: 109
|
|
|
|
mijanurit wrote: |
hi davidatk,
plz tell me in details for the following ...
Quote:
01 filler
05 x pic x(5).
05 y redefines x pic 9(5).
when x=123 3
what is the content of y?
in case of x=123 z OR x='123=3' what will be the content of y if y is declared as pic s9(5)?
thanks and regards
mijanurit |
hai mijanurit,
i suppose the value of Y will also contain the same data as that of X. Rediefines simply share the memory space irrespective of their PIC.
corrections welcomed...
gowtham |
|
Back to top |
|
|
vinodmaanju
New User
Joined: 10 May 2005 Posts: 28 Location: Pune
|
|
|
|
Hi mijanurit,
Output will be same as X. coz redefines share same memory locatiom from starting bytes according your length of Y.
Thanks
Vinod |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Hi mijanurit,
Both vinodmaanju and gowtham_1982 are correct. the 9(5) field will contain the same hex value as the X(5) field. the difference come when you try to use the field.
First, you understand the hex representation of the numbers?
Shown below are 0-9 0 = x?F0?, 1 = x?F1? etc.
Code: |
0123456789
FFFFFFFFFF
0123456789
|
Given a PIC 9(5) value 12345
This is an unsigned field where the hex value will be ?F1F2F3F4F5?. When addition is performed on this only the low order 4 bits of each byte are considered for the magnitude of the value. The high order 4 bits do not play any part, the sign is assumed to be + (positive).
Given a PIC S9(5) value +12345
This is a signed field where the hex value will be ?F1F2F3F4C5?. ?F1F2F3F4D5? if the value was -12345. When addition is performed only the low order 4 bits are considered for the magnitude of the number and the high order 4 bits of the last byte is considered for the sign.
Normally in a PIC S9(?) field the sign 4 bits will be ?C? = ?+? and ?D? = ?-?.
Now, when addition is performed on a PIC 9(?) or S9(?) field. The field is converted to COMP-3, the addition performed, and converted back to zoned decimal.
When you convert a zoned decimal number to a PIC 9(?) COMP-3 (unsigned) anything can be in the sign bits (x?0? ? x?F?) When converted, the COMP-3 sign bits will always be x?F? and when converted back to the zoned decimal format the sign bits x'F' will remain.
When you convert a zoned decimal number to a PIC S9(?) COMP-3 (Signed) only x?A? ? x?F? can be in the sign bits.
x?A?,x?C?,x?E?,x?F? will be ?+? and x?B?, x?D? will be ?-?. When converted the sign bits will always be either x?C? or x?D?. Anything other than x?A? ? x?F? will cause an 0C7 abend. The sign bits of s successfull add x'C' or 'D' will remain when converted back to zoned decimal.
In both cases, signed and unsigned, anything in the low order 4 bits of each byte other than x?0? ? x?9? will cause an 0C7 abend.
That?s why, when you redefine a PIC X(5) VALUE = ?123 3? as a PIC 9(5) or as a PIC S9(5) the space is converted to a 0 (zero). The hex value of the space is x?40?. This is not the sign byte, so the high order 4 bits the ?4? is ignored, and the low order 4 bits '0' are x?0? ? x?9?.
The ?123 3? is converted to VALUE 12303. x?F1F2F3F0F3? for PIC 9(5) and x?F1F2F3F0C3? for S9(5)
And that?s why you will get an 0C7 abend if your try ?123=3? because the ?=? = x?7E?. The 'E' is not x'0' - x'9'
Or when you try ?1234.? Where ?.? = x?90? and if you try to add to an S9(5) you get an 0C7. The '9' is the sign bits and not one of the allowed values. And converts to ?12340? if you add to an 9(5) because the sign bits are ignored. |
|
Back to top |
|
|
|