Author: monica1
Subject: Incorrect output when trying to add numbers
Posted: Fri Jan 13, 2017 5:02 pm (GMT 5.5)
Hi,
I am a newbie in Assembler programming.
In the current program that I am working on, I am trying to:
1) Read records from an input file.
2) Convert the first two characters (basically has my numbers) to Packed decimal using PACK instruction
3) Adding the numbers
4) Converting packed decimal result back to character using UNPK
5) Writing the record into output file.
Below is the program that I am using.
* READ NUMBERS FROM I/P FILE, ADD AND PLACE RESULT IN O/P FILE
FLEADNU CSECT
STM 14,12,12(13)
BALR 12,0
USING *,12
ST 13,SAVE+4
LA 13,SAVE
OPEN (INDCB,(INPUT))
OPEN (OUTDCB,(OUTPUT))
WTO 'DISPLAY1'
IOLOOP MVC INAREA,=80C' '
WTO 'DISPLAY2'
ZAP TEMPNUM,ZEROES
GET INDCB,INAREA
PACK TEMPNUM,INPNUM
AP TOTAL,TEMPNUM
WTO 'DISPLAY3'
B IOLOOP
FINISH UNPK OUTNUM,TOTAL
WTO 'DISPLAY4'
PUT OUTDCB,OUTAREA
CLOSE (INDCB)
CLOSE (OUTDCB)
EXIT L 13,SAVE+4
LM 14,12,12(13)
XR 15,15
BR 14
INDCB DCB DSORG=PS,MACRF=(GM),DDNAME=TESTIN,EODAD=FINISH, X
RECFM=FB,LRECL=80,BLKSIZE=0
OUTDCB DCB DSORG=PS,MACRF=(PM),DDNAME=TESTOUT, X
RECFM=FB,LRECL=80,BLKSIZE=0
INAREA DS 0CL80
INPNUM DS CL2
FILLER DS CL78
OUTAREA DS 0CL80
OUTNUM DS CL2
FILLER1 DS CL78' '
OUTLINE DC CL80' '
TOTAL DC PL2'0'
TEMPNUM DC PL2'0'
ZEROES DC PL2'0'
SAVE DS 18F
END
My input and output records are 80 bytes.
I am giving the below inputs in my input file.
10
20
30
05
And I am getting the below in the output file.
06E
Could you help me out here in understanding why the result is coming as 06E instead of the expected result 65.
Thanks in advance.
Subject: Incorrect output when trying to add numbers
Posted: Fri Jan 13, 2017 5:02 pm (GMT 5.5)
Hi,
I am a newbie in Assembler programming.
In the current program that I am working on, I am trying to:
1) Read records from an input file.
2) Convert the first two characters (basically has my numbers) to Packed decimal using PACK instruction
3) Adding the numbers
4) Converting packed decimal result back to character using UNPK
5) Writing the record into output file.
Below is the program that I am using.
* READ NUMBERS FROM I/P FILE, ADD AND PLACE RESULT IN O/P FILE
FLEADNU CSECT
STM 14,12,12(13)
BALR 12,0
USING *,12
ST 13,SAVE+4
LA 13,SAVE
OPEN (INDCB,(INPUT))
OPEN (OUTDCB,(OUTPUT))
WTO 'DISPLAY1'
IOLOOP MVC INAREA,=80C' '
WTO 'DISPLAY2'
ZAP TEMPNUM,ZEROES
GET INDCB,INAREA
PACK TEMPNUM,INPNUM
AP TOTAL,TEMPNUM
WTO 'DISPLAY3'
B IOLOOP
FINISH UNPK OUTNUM,TOTAL
WTO 'DISPLAY4'
PUT OUTDCB,OUTAREA
CLOSE (INDCB)
CLOSE (OUTDCB)
EXIT L 13,SAVE+4
LM 14,12,12(13)
XR 15,15
BR 14
INDCB DCB DSORG=PS,MACRF=(GM),DDNAME=TESTIN,EODAD=FINISH, X
RECFM=FB,LRECL=80,BLKSIZE=0
OUTDCB DCB DSORG=PS,MACRF=(PM),DDNAME=TESTOUT, X
RECFM=FB,LRECL=80,BLKSIZE=0
INAREA DS 0CL80
INPNUM DS CL2
FILLER DS CL78
OUTAREA DS 0CL80
OUTNUM DS CL2
FILLER1 DS CL78' '
OUTLINE DC CL80' '
TOTAL DC PL2'0'
TEMPNUM DC PL2'0'
ZEROES DC PL2'0'
SAVE DS 18F
END
My input and output records are 80 bytes.
I am giving the below inputs in my input file.
10
20
30
05
And I am getting the below in the output file.
06E
Could you help me out here in understanding why the result is coming as 06E instead of the expected result 65.
Thanks in advance.