IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Incorrect output when trying to add numbers


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
monica1

New User


Joined: 05 Jan 2017
Posts: 5
Location: Bangalore

PostPosted: Fri Jan 13, 2017 5:02 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Jan 13, 2017 5:34 pm
Reply with quote

You are seeing 06E because the sum is a positive number. The packed number is x'065C' which unpacks as C'6E', because X'C5' whicnis the last byte unpacked is the letter 'E'.

What you need to do, after the
Code:
FINISH UNPK OUTNUM,TOTAL
instruction is to make the last digit printable as a number. This is achieved by adding the instruction
Code:
       OI  UNPACK+1, X'F0' 
after the UNPK.

Garry
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Fri Jan 13, 2017 5:48 pm
Reply with quote

  • Post this query in the Help & Support Forum for Mainframe Beginners. This forum is supposed to be for more advanced users.
  • When you post code, like your little program, surround it by phpBB code tags. You can find out about these tags by using Google.
  • Carefully read and understand the discussion about the zoned decimal, packed decimal, and decimal codes, and the UNPK instruction in Principles of Operation. Zoned decimal does not necessarily mean 100% readable, though 100% readable is usually acceptable to the PACK instruction and subsequent decimal arithmetic instructions. The last paragraph in the decimal codes topic will explain why.
  • One additional instruction is typically used after the UNPK instruction to update the zoned decimal sign to make the zoned decimal number 100% readable. You can also used the same instruction, though with different data, to update the sign in the packed decimal data before you use the UNPK instruction. At various times in my career I've used both solutions. Hint: this instruction is not a "decimal" instruction.
Back to top
View user's profile Send private message
monica1

New User


Joined: 05 Jan 2017
Posts: 5
Location: Bangalore

PostPosted: Mon Jan 16, 2017 8:37 am
Reply with quote

Thanks for the response and apologies for posting the query in the wrong forum. I have registered myself in the beginners forum and waiting for the account to be activated.

In the meantime, I tried using the instruction that Garry has provided. I added the code after the UNPK instruction.

But I am getting an error during the compilation process.

** ASMA141E Bad character in operation code - UNPACK+1,X'FO'

Could you let me know what might be the reason.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 419
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Mon Jan 16, 2017 8:51 am
Reply with quote

X'F0' fox zero not x'FO'
Back to top
View user's profile Send private message
monica1

New User


Joined: 05 Jan 2017
Posts: 5
Location: Bangalore

PostPosted: Mon Jan 16, 2017 9:17 am
Reply with quote

I tried with this instruction

OI OUTNUM+1,X'F0'

instead of

OI UNPACK+1,X'F0'

and I was able to execute the program.

From this I understand that an OI instruction should be performed on the UNPK-ed tagname inorder to make the last digit as printable.

Thanks everyone for your help.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Jan 16, 2017 3:45 pm
Reply with quote

monica1 wrote:
Thanks for the response and apologies for posting the query in the wrong forum. I have registered myself in the beginners forum and waiting for the account to be activated.

In the meantime, I tried using the instruction that Garry has provided. I added the code after the UNPK instruction.

But I am getting an error during the compilation process.

** ASMA141E Bad character in operation code - UNPACK+1,X'FO'

Could you let me know what might be the reason.

The query that started this topic, as well as this second query demonstrated an unwillingness to think or to use existing reference material. Since knowing where, in the wealth of available documentation that is now available, to go, my first response pointed out where to go rather than directly answer your query. It still depended on your ability to THINK about a problem. This second query reinforced this conclusion. I must admit I, too, as well as dneufarth made the same error.

I wrote this little program to try to recreate the error.
Code:
HEX      CSECT
         USING *,15
         OI    DATA+1,X'FO'
         SR    15,15
         BR    14
DATA     DC    P'55'
         END   HEX

When I ran it through HLASM I got this error message -

** ASMA148E Self-defining term lacks ending quote or has bad character - X'FO'

rather than the ASMA141E message.

Both dneufarth and I didn't bother to read the entire ASMA141E message to realize your statement was

UNPK+1,X'FO'

We both jumped to the X'FO' and analyzed it, rather than analyze the real problem.

Now let's look at X'FO'.

Arguably there are at least two possible issues here.
  1. Your understanding of hexadecimal notation.
    Hexadecimal notation has 16 unique digits: 0 through 9, and A through F are usually used to represent the additional 6 digits. So it would seem there is something wrong with FO.
  2. The font (the way the characters are formed on screen or printed)
    One nice thing about the font as printed by IBM 1403 printer is it was easy to distinguish between the letter O and the number 0. Seeing the O and 0 side by side it it is easy to see the difference, but seeing X'FO' it is rather to easy to see what should be a 0 is really O. Sadly I can't easily recreate this font here, though I have seen fairly good attempts elsewhere in the internet. The letter O was not a simple circle; rather it is was more like a small square. The number 0 had a single dot in the middle. The two IBM keypunch machines of the 1960s used a similar font in the characters it could print on the cards it punched.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 419
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Tue Jan 17, 2017 12:28 am
Reply with quote

machine instruction looks like 96F0bddd. 'b' = base register and 'ddd' = displacement


96FO (opcode & immediate data) is the offender in the error msg

At least that's what I recall from years ago.


Steve, good insight in your post. I went straight to solve the problem.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Tue Jan 17, 2017 7:56 am
Reply with quote

dneufarth wrote:
machine instruction looks like 96F0bddd. 'b' = base register and 'ddd' = displacement


96FO (opcode & immediate data) is the offender in the error msg

At least that's what I recall from years ago.


Steve, good insight in your post. I went straight to solve the problem.

dneufarth still doesn't get it. The failing line probably was something like
Code:
OI UNPACK+1,X'FO'
to get the ASMA141E error. In other words, the OI was considered a label, and HLASM thought UNPACK+1,X'FO' was an instruction of some sort.
Back to top
View user's profile Send private message
monica1

New User


Joined: 05 Jan 2017
Posts: 5
Location: Bangalore

PostPosted: Tue Jan 17, 2017 8:20 am
Reply with quote

Hi Steve,

I had initially given the OI instruction in a wrong column and hence it was considered as a label instead of an instruction.

Later, when I placed it in the correct column, it worked fine.

Thank you.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 419
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Tue Jan 17, 2017 8:25 am
Reply with quote

I yield to Steve. Thanks for the clarification.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
Search our Forums:

Back to Top