## Learning AP instruction - need some help

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

### Learning AP instruction - need some help

I am trying to learn the intricacies behind AP instruction and am facing a situation.

Below goes the question ::

Given W DC PL2'10', X DC PL2'-6', Y DC CL2'15', and Z DC PL2'8'. Write the BAL code to
determine Z = W + X + Y . Show the hex representation of Z after each instruction. Your final
answer for Z should be X'019C'. (Reminder: Y must be packed before it can be added.
Define a work field if necessary.)

Above question is from assembler book of Bill Qualls

I can understand that W+X+Y = 10 + (-6) + 15 = 19 and the hex representation of 19 in PL2 would be X'019C'. ------- Step 1

What I cannot understand is the hex addition of W+X+Y
Hex representation of W DC PL2'10' = X'010C'
Hex representation of X DC PL2'-6' = X'006D'
Hex representation of Y DC CL2'15' = X'F1F5' = in packed format = X'015F'
W+X = 010c + 006D = 0179
W+X+Y = 0179 + 015F = 02D8

Now how come 02D8 is different from 019C as deducted in Step 1 above. Can somebody pls help me in understanding this?
fast_learner

Posts: 9
Joined: Wed Aug 22, 2012 9:39 pm
Has thanked: 0 time
Been thanked: 0 time

### Re: Learning AP instruction - need some help

W is packed
X is packed
Y is NOT packed... is a char

hence the suggestion to use an auxiliary/work variable
(Reminder: Y must be packed before it can be added. Define a work field if necessary.)

in the declarative part
...
*2345678901234567890
YP       DS    Cl2
...

in the instruction part before adding <Y>

...
*2345678901234567890
PACK  YP,Y
AP    <total>,YP
...
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator

Posts: 2692
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 138 times

### Re: Learning AP instruction - need some help

Hello and welcome to the forum,

I believe you need to step Way back and begin again.

Some of your "truths" are not true.
Hope this helps,
d.sch.

dick scherrer
Global moderator

Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

### Re: Learning AP instruction - need some help

Thanks for the reply but I am still not able to get an answer to my query.

In totality can somebody write the BAL code to determiner z= W+ X+ Y and show the hex representation of Z after each instruction. We can very well presume that Y has been packed into PK2 DC PL2'0' using the instruction PACK PK2,Y.

The final answer for Z must have the hex representation as X'019C'.
fast_learner

Posts: 9
Joined: Wed Aug 22, 2012 9:39 pm
Has thanked: 0 time
Been thanked: 0 time

### Re: Learning AP instruction - need some help

Now how come 02D8 is different from 019C as deducted in Step 1 above. Can somebody pls help me in understanding this?

You should use only the numeric part ...
rightmost half byte which is the sign

W  010 C==> positive
X  006 D==> negative
YP 015 F==> positive

10-6+15 ==> 19

z  019 C==> positive
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator

Posts: 2692
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 138 times

### Re: Learning AP instruction - need some help

OPEN  (SNAPO,(OUTPUT))
PACK  DBLWORD,Y
CVB   R11,DBLWORD
ZAP   Z,W
AP    Z,X
AP    Z,DBLWORD+6(2)
CLOSE (SNAPO)
* RESTORE REGISTERS AND RETURN WITH RC=0
L     R13,4(R13)
LM    R14,R12,12(R13)
XR    R15,R15
BR    R14
LTORG
**************************************************
*       STORAGE FOR MAIN                         *
**************************************************
MAINSAVE DS    18F
W        DC    PL2'10'
X        DC    PL2'-6'
Y        DC    CL2'15'
Z        DC    PL2'8'
DBLWORD  DC    D'0'
*
SNAPO    DCB   DDNAME=SYSOUT,BLKSIZE=1632,DSORG=PS,LRECL=125,MACRF=(W),X
RECFM=VBA
produces results (extracted) of
244         STEP STEP1           TIME 134553   DATE 12235    ID = 001    CPUID =

ENTRY TO SNAP    078D1000  00007E42  ILC  02  INTC  0033

010C006D F1F5008C   *
00000000 00000000 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 001

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
MP
244         STEP STEP1           TIME 134553   DATE 12235    ID = 002    CPUID =

ENTRY TO SNAP    078D1000  00007E72  ILC  02  INTC  0033

010C006D F1F5008C   *
00000000 0000015F 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 002

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
MP
244         STEP STEP1           TIME 134553   DATE 12235    ID = 003    CPUID =

ENTRY TO SNAP    078D1000  00007EA2  ILC  02  INTC  0033

010C006D F1F5008C   *
00000000 0000015F 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 003

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
MP
244         STEP STEP1           TIME 134553   DATE 12235    ID = 004    CPUID =

ENTRY TO SNAP    078D1000  00007ED2  ILC  02  INTC  0033

010C006D F1F5010C   *
00000000 0000015F 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 004

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
MP
244         STEP STEP1           TIME 134553   DATE 12235    ID = 005    CPUID =

ENTRY TO SNAP    078D1000  00007F02  ILC  02  INTC  0033

010C006D F1F5004C   *
00000000 0000015F 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 005

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
MP
244         STEP STEP1           TIME 134553   DATE 12235    ID = 006    CPUID =

ENTRY TO SNAP    078D1000  00007F32  ILC  02  INTC  0033

010C006D F1F5019C   *
00000000 0000015F 00000000                                                   *..
244         STEP STEP1           TIME 134553   DATE 12235    ID = 006

DUMP INDEX
----------
AS                                               PAGE NUMBER
--                                               -----------
ATED TO TCB AT: 008FF890/....                    00000001
REAS.........................                    00000001
which shows you precisely what is in memory each step of the way. Adding PDATA=(REGS) to the SNAP statement would add the registers, but that adds a lot of lines to the display and doesn't really provide much assistance in this particular case. The program output variables start 010C006D and go to the next line in each output (watch for ID = nnn to change).
Robert Sample
Global moderator

Posts: 3431
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 239 times

### Re: Learning AP instruction - need some help

Hello,

My earlier reply has been "cropped" as i got crossed up and the info was basically useless

Sorry 'bout that,

d

dick scherrer
Global moderator

Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

### Re: Learning AP instruction - need some help

There are two "ringers" here.
• The initial value of Z does not figure into the final value of Z.
• Y is defined as character, which for the purposes of this exercise can be considered to be zoned decimal. It has to be converted to packed decimal before it can be used.
Mr. Scherrer's analysis about packed decimal signs is incorrect. There is no such thing as a hexadecimal O (character O, not digit 0). A packed decimal sign is the last 4 bits (1 hexadecimal digit) of a packed decimal value. There are two classes of packed decimal signs.
• "Preferred" signs: C for positive and D for negative. The packed decimal instructions always generate a "preferred" sign. To a lazy eye, D often looks like O,
• Alternate signs: A, B, E and F. The only one I have memorized is F, which is considered to be positive.

PACK TEMP,Y
...
Y DC CL2'15' (X'F1F5')
TEMP DC PL2'0'

creates X'015F' in TEMP, which packed decimal arithmetic considers to be the equivalent of PL2'15'.
Now I'm not going to to insert my solution here: this is your homework,after all, and you will learn more by doing it yourself and not copying my solution.
steve-myers
Global moderator

Posts: 1916
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 206 times

### Re: Learning AP instruction - need some help

Thanks to one and all for the replies.

I am aware of the code solution that would give me the desired result of Z having the hex representation of x'019c'.
What is bemusing me is the individual steps towards the solution.

If somebody can depict the actual hexadecimal addition that takes place here to reach x'019c' - this would help me a lot in solving my actual doubt.

My hexadecimal addition gives me a result of x'02D8' [010C+006D+015F = 02D8] as depicted in the actual question but how can that be equal to the correct answer which is x'019C'?

Please note - I have assumed that Z would be first filled with zeroes using ZAP and then it will be used to store the addition of W+X+Y.
fast_learner

Posts: 9
Joined: Wed Aug 22, 2012 9:39 pm
Has thanked: 0 time
Been thanked: 0 time

### Re: Learning AP instruction - need some help

Hi Robert -

I am extremely grateful to you. I studied your reply and it did helped me a lot to understand the intricacy behind AP instruction and would go a long way in building my concepts.

On the same note - can I request one more favour from you? Do you have any 'Emulator' using which I can run Assembler programs on my personal PC. If yes can you pls share the same with me. This would help me in practically solving the exercise.
fast_learner

Posts: 9
Joined: Wed Aug 22, 2012 9:39 pm
Has thanked: 0 time
Been thanked: 0 time

Next