Packing, Editing, and Unpacking



High Level Assembler(HLASM) for MVS & VM & VSE

Packing, Editing, and Unpacking

Postby RISCCISCInstSet » Thu Dec 01, 2011 1:25 am

In this topic I'm trying to figure out what kinds of things go wrong when using the pack instruction, editing the number, unpacking, and then sending to a file.

I've already tried to "RTFM;" it's all kind of a mish-mash to me - apparently the pack instruction packs characters into numeric data, unpk does the opposite, OI is used for changing the last digit of a data value to F to make it unpkable, and mvc moves characters into data variables, AP adds packed decimal, A adds full words, st stores data from registers into variables, l does the opposite, ds defines variables, dc defines constants, PLx defines a packed decimal with x digits, clx defines a string with x characters. xc seems to be similar to clx, but I'm a little confused as to how it works.

Thanks for any help.
RISCCISCInstSet
User avatar
RISCCISCInstSet
 
Posts: 121
Joined: Mon Oct 17, 2011 1:46 pm
Has thanked: 146 times
Been thanked: 0 time

Re: Packing, Editing, and Unpacking

 

Re: Packing, Editing, and Unpacking

Postby Robert Sample » Thu Dec 01, 2011 2:14 am

Forget the manual -- you need to find a good Assembler book (like Struble) and study it.
OI is used for changing the last digit of a data value to F to make it unpkable
This is pretty much like saying a car is used to burn gasoline -- true as far as it goes but vastly understating things.

Your terminology is so imprecise that there is no way to determine what you know. From your post, it does not appear that you understand anything about the architecutre of a z system. If you cannot learn how the z system stores a binary number, a packed decimal number, a floating point number, a zoned decimal number, and characters -- you won't really need to understand the various instructions your post mentioned.

These users thanked the author Robert Sample for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Packing, Editing, and Unpacking

Postby BillyBoyo » Thu Dec 01, 2011 5:45 am

This is an unsigned five-byte number. It is also a five-byte character field. Can be called Zoned Decimal, External Decimal, Display numeric.

 1 2 3 4 5
F1F2F3F4F5

This is the would be the result of packing the above field.

12345F

This would be the result of unpacking it again.

 1 2 3 4 5
F1F2F3F4F5


However

B1C2D3E4F5

packs to

12345F

and unpacks to
F1F2F3F4F5


In hexadecimal notation, each byte appears as two characters, 0-F, which represent all the 256 possible bit-settings of one byte (0-FF).

The half-of-a-byte represented by 0-F is called a "nybble". For a Zoned Decimal format (which is just a convention) the right-nybble is called the Numeric and the left-nybble is called the Zone, except for the right-most left nybble which is the sign-nybble.

When you use the pack instruction all of the zones are tossed away, which means their original content is irrelevent to the instruction.
The right-nybbles are placed side by side and the sign from the Zoned Decimal sign-nybble is placed in the Packed Decimal sign-nybble, which is the right-most right nybble.

On the way back, unpacking, all the Zones are set to F, otherwise everything from the Packed Decimal, including the sign, is distributed in a logical way.

There are no arithmetic instructions for Zoned Decimals. There are for Packed Decimals. Packed Decimals ocupy less storage, in memory and on mass storage media.

These users thanked the author BillyBoyo for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Packing, Editing, and Unpacking

Postby RISCCISCInstSet » Thu Dec 01, 2011 7:16 am

Thank you for your response.

Apparently after a number has just been packed, you get an unsigned decimal (you stated that). When you run an arithmetic operation on it, you get a signed decimal, with a C in the rightmost part of its hex representation.

To unpk that, I apply OI num+n,X'0F' before unpking or OI char+n,X'F0' after unpacking. Here, byte gets or'ed to make the number (positive) unsigned again. You might use one statement or the other depending on whether you apply it before or after the sign byte gets flipped. n is 1 less than how long your variable is.
RISCCISCInstSet
User avatar
RISCCISCInstSet
 
Posts: 121
Joined: Mon Oct 17, 2011 1:46 pm
Has thanked: 146 times
Been thanked: 0 time

Re: Packing, Editing, and Unpacking

Postby steve-myers » Thu Dec 01, 2011 10:39 am

RISCCISCInstSet wrote:Apparently after a number has just been packed, you get an unsigned decimal (you stated that) ...
Not true. All packed decimal data is signed.

It really goes back to representing data on punched cards. The classic IBM punched card has 80 columns of data in 12 rows. The bottom 10 rows were used for decimal digits. The top two rows were potentially used to indicate the bottom 10 rows were something other than a number. The top row was called the "12" row, the second row was called the "11" row. These rows were used to indicate the sign of numeric data when they were placed over the last byte of a numeric field. A column punched as 12-0 was a positive 0, a row punched as 11-0 was a negative 0, 12-1 and 11-1 were positive and negative 1, and so on. The card equipment that preceded computers were designed to work this way. In the early 1960s there were still millions of cards prepared using this convention, and relatively few computers compared to card sorting machines.

The people that designed the System/360 computers and EBCDIC were fully aware of this convention, so no punch in rows 12 and 11, and a punch in rows 0 through 9 were assigned EBCDIC codes X'F0' through X'F9'. 12 + 0 through 9 were assigned EBCDIC codes X'C0' through X'C9', and 11 + 0 through 9 were assigned EBCDIC codes X'D0' through X'D9'. See the pattern? This is the origin of the preferred and at least some of the alternate packed decimal and zoned decimal signs. 12 + 1 through 9 were also the codes for A through I, and 11 + 0 through 9 were the codes for J through R.

These users thanked the author steve-myers for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
steve-myers
Global moderator
 
Posts: 1886
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Packing, Editing, and Unpacking

Postby dick scherrer » Thu Dec 01, 2011 12:23 pm

Hello,

Apparently after a number has just been packed, you get an unsigned decimal (you stated that) ...
You have misunderstood.

As has been mentioned, all packed decimal values have a sign.

Also, buying a good book on assembler has been recommended. This would not be the "manuals", but rather a book meant to introduce new people to the assembler language and get them thru the initial learning (which is often some sincere work). My personal favorite has been the Assembler book written by Kevin McQuillen. This was written n the mid-70's and can sometimes be found and sometimes there is nonoe for sale.

Kevin has a newer assembler book co-authored with Anne Prince. Several people have told me good thoings about it, but i don't have a copy.

IBM still has some training, but i don't know the specifics. A quick search found this:
http://www-304.ibm.com/jct03001c/servic ... de=EB460CE
Do note the price is $3,000.00 . . .

Unless this will become the main part of your job, i believe one or 2 good books backed up by the IBM manuals will provide what you need. As i believe i mentioned elsewhere - this will take time. For example, at a university where i was a tecnical mentor from 1970 thru 1985 (assembler, cobol, jcl/utilities, data organization/structures and on and on) the assembler training was a full year of 5-hour classes plus labs. In that system one hour meant the class lecture was 1 hour a week - a 5-hour class was an hour 5 days a week. Then there were the labs that might go into entire weekends when people had projects due. Lots of students fell somewhat behind in only a month or so and the class went the full school year. Of course the ones who successfully sompleted all of this plus the "other stuff" were in great demand.

This is not meant to be discouraging but give an idea of how much meterial there is in assembler alone.
Hope this helps,
d.sch.

These users thanked the author dick scherrer for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Packing, Editing, and Unpacking

Postby BillyBoyo » Thu Dec 01, 2011 6:29 pm

RISCCISCInstSet wrote:[...]

Apparently after a number has just been packed, you get an unsigned decimal (you stated that). When you run an arithmetic operation on it, you get a signed decimal, with a C in the rightmost part of its hex representation.

To unpk that, I apply OI num+n,X'0F' before unpking or OI char+n,X'F0' after unpacking. Here, byte gets or'ed to make the number (positive) unsigned again. You might use one statement or the other depending on whether you apply it before or after the sign byte gets flipped. n is 1 less than how long your variable is.


Apparently nothing. I chose examples with Fs in the sign as you had referred to or-ing to make F.

Inputs to decimal arithmatic (which includes the ZAP instruction) can have A through F, inclusive, in the sign nybble. The output sign nybble will always be C or D depending on the logical value (positive or negative) of the result. Multiply 1F by 1D, result will be 1C. Multiply 1B by 1D and the result will be 1C.

Sign byte gets flipped? The code you are showing is to ensure that a packed-decimal has F in the sign (first OI) and that a zoned-decimal has F in the sign (second OI).

Like others, I still think you need a better grounding before ploughing ahead (mix of metaphors deliberate, but irrelevant to the topic).

These users thanked the author BillyBoyo for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Packing, Editing, and Unpacking

Postby steve-myers » Thu Dec 01, 2011 7:58 pm

Actually 1F * 1D = 1D ( +1 * -1 = -1) 1B * 1D = 1C (-1 * -1 = +1). The examples won't assemble as written, but altered to assemble correctly they produce the results shown.

These users thanked the author steve-myers for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
steve-myers
Global moderator
 
Posts: 1886
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Packing, Editing, and Unpacking

Postby BillW » Thu Dec 01, 2011 8:06 pm

What you really need to do is to get access to a 370 emulator for your PC that allows you to directly plug in the instructions and data contents into memory. Using such a tool (and you could use an assembler listing and copy instructions) and perhaps the little yellow card that lists the instructions and the EBCIDIC values, plug in the various instructions into said tool and single step through them. I found where it was most informative and you can see exactly what happens after each instruction by inspecting memory and registers (current psw and a good bet is the program check old psw). Thats how I learned PC assembler and how I learned much about 370 using the IBM VM/370 capabilities to do the same. You need this type of interaction to better acquaint yourself with how the IBM mainframe instructions and data formats look and feel. You could use this in conjunction with the principles of operations to learn the hardware (I would skip the privileged stuff for now). This is just my humble opinion and others will see it differently and it is only a suggestion, but you seem to need more time with the basics.

These users thanked the author BillW for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
BillW
 
Posts: 20
Joined: Thu Nov 10, 2011 8:21 am
Has thanked: 0 time
Been thanked: 3 times

Re: Packing, Editing, and Unpacking

Postby BillyBoyo » Thu Dec 01, 2011 8:28 pm

steve-myers wrote:Actually 1F * 1D = 1D ( +1 * -1 = -1) 1B * 1D = 1C (-1 * -1 = +1). The examples won't assemble as written, but altered to assemble correctly they produce the results shown.



Thanks Steve. I tried to show one of each sign, and managed to mess it up :-)

These users thanked the author BillyBoyo for the post:
RISCCISCInstSet (Mon Nov 12, 2012 4:55 am)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times


Return to Assembler