## Instruction for adding zoned decimals

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

### Instruction for adding zoned decimals

Hi all,
I want to know about the instruction in assembly for adding zoned decimal.
tanu_2302

Posts: 9
Joined: Tue Nov 08, 2016 12:45 pm
Has thanked: 1 time
Been thanked: 0 time

### Re: Instruction for adding zoned decimals

What did you find out when you looked in the manuals?
Robert Sample
Global moderator

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

### Re: Instruction for adding zoned decimals

There are no instructions for adding two zoned decimal numbers. Convert them to packed decimal, add them, and convert the result to zoned decimal if this is a "real" requirement. For example -
AZP      CSECT
DATA     DSECT
FIELD1   DS    ZL3
FIELD2   DS    ZL3
FIELD3   DS    ZL4
AZP      CSECT
USING *,12
SAVE  (14,12),,*
LR    12,15
LA    15,SAVEAREA
ST    13,4(,15)
ST    15,8(,13)
LR    13,15
OPEN  (INPUT,INPUT,OUTPUT,OUTPUT)
LOOP     GET   INPUT
LR    2,1
USING DATA,2
PACK  DBL1,FIELD1
PACK  DBL2,FIELD2
AP    DBL2,DBL1
UNPK  FIELD3,DBL2
PUT   OUTPUT
MVC   0(80,1),0(2)
B     LOOP
EOD      CLOSE (INPUT,,OUTPUT)
L     13,4(,13)
RETURN (14,12),RC=0
SAVEAREA DC    9D'0'
DBL1     DC    PL8'0'
DBL2     DC    PL8'0'
OUTPUT   DCB   DSORG=PS,MACRF=PL,DDNAME=OUTPUT,                       ->
RECFM=FB,LRECL=80
END   AZP

*** RECORD 1

0000     0  F1F2F3F4 F5F64040  40404040 40404040  *123456          *
0010    16  40404040 40404040  40404040 40404040  *                *
ONE OR MORE LINES SAME AS PREVIOUS LINE
0040    64  40404040 40404040  40404040 40404040  *                *

*** RECORD 2

0000     0  F9F9F9F9 F9F94040  40404040 40404040  *999999          *
0010    16  40404040 40404040  40404040 40404040  *                *
ONE OR MORE LINES SAME AS PREVIOUS LINE
0040    64  40404040 40404040  40404040 40404040  *                *

*** RECORD 1

0000     0  F1F2F3F4 F5F6F0F5  F7C94040 40404040  *123456057I      *
0010    16  40404040 40404040  40404040 40404040  *                *
ONE OR MORE LINES SAME AS PREVIOUS LINE
0040    64  40404040 40404040  40404040 40404040  *                *

*** RECORD 2

0000     0  F9F9F9F9 F9F9F1F9  F9C84040 40404040  *999999199H      *
0010    16  40404040 40404040  40404040 40404040  *                *
ONE OR MORE LINES SAME AS PREVIOUS LINE
0040    64  40404040 40404040  40404040 40404040  *                *
A little program appears first followed by an example of an input data set and then the output data set in a dump format.

For you beginners. -
• An Assembler DSECT is a sort of picture of a data area.
• The INPUT DCB specifies MACRF=GL. The GET macro returns the address of the data record in register 1. The program copies this address to register 2.
• Similarly, the OUTPUT DCB specifies MACRF=PL. A PUT macro actually writes the data area returned by the previous PUT macro and then returns the address of the next data area to write in register 1. Your program must add data to this output record before it executes the next PUT macro.
• The PACK macro transform a zoned decimal data area to a packed decimal area. Any missing data in the zoned decimal input becomes 0 in the output area. So a zoned decimal data area C'123' becomes X'0000000000000123F'. The F at the end is an alternate packed decimal plus. So 123+456 becomes x'579C', or P''+579'. UNPK converts this to x'f5f7c9'. This is a valid zoned decimal value.
• I usually define a save area as 9 double words rather than 18 full words. This results in the same 72 bytes and ensures the next bytes will be on a double word boundary.
steve-myers
Global moderator

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

### Re: Instruction for adding zoned decimals

thanks
tanu_2302

Posts: 9
Joined: Tue Nov 08, 2016 12:45 pm
Has thanked: 1 time
Been thanked: 0 time