On 3/15/2013 12:22 PM, Forst, Fred wrote:
I'm just starting to learn assembler, so I started with 'Hello World' and also printing the sum of 2 numbers. Snippet of the code is below and it works fine:OPEN (SYSPRINT,(OUTPUT)) Write output here L 3,NUM1 Load first number in R3 L 4,NUM2 Load 2nd number in R4 AR 4,3 Add contents of R4 and R3 and store * in R4 PUT SYSPRINT,MSG01 Write Hello World to SYSPRINT * * Output the value in RESULT * MVC MSG01,=C'Result= ' CVD R4,CONV1 UNPK MSG01B,CONV1+4(4) OI MSG01B+6,X'F0' PUT SYSPRINT,MSG01 CLOSE (SYSPRINT) Close SYSPRINT NUM1 DC F'9' Hardcoded first number NUM2 DC F'4' Hardcoded second number SYSPRINT DCB DDNAME=SYSPRINT, + MACRF=(PM), + DSORG=PS,RECFM=F,LRECL=80 * * Output line: Fields add to 80 * DC - Character field * DS - Numeric field * * MSG01 DC CL11'Hello World' Store string here MSG01B DS CL7 numeric field MSG01B2 DC C' ' MSG01C DC CL62' ' padding END NEWTON3 End of program But the printing part doesn't work if NUM1 & NUM2 have decimal points (e.g. 4.3 & 6.1). If I use ADBR to add the 2 numbers and store as BFP and try to print that, I get garbage. Can someone show what has to change in the code for this to work? Thanks. L 3,NUM1 Load first number in R3 L 4,NUM2 Load 2nd number in R4 ADBR 4,3 Add contents of R4 and R3 and store * in R4
You're mixing things up a lot. First, NUM1 and NUM2 are fullword binary integers. So you add them together; fine; then you CVD the result into CONV1: you haven't shown us how you define this field but it better be: CONV1 DS D So, your CVD instruction puts a binary number into packed decimal format in CONV1; UNPK will convert this to zoned decimal except the rightmost byte will include a sign indicator. If you want to display the result with a decimal point, look at the ED (edit) instruction. Note that just because a number includes a (logical) decimal point does not make it a floating point number. It's still just a decimal number. Floating point is a whole nother set of formats; you can't use a floating point add (ADBR) with binary digit values and expect to get any kind of meaningful results. You might find my SHARE presentation "Doing Packed Decimal Arithmetic in Assembler" useful: http://www.share.org/p/do/sd/topic=160&sid=3068 hope this helps. -- Kind regards, -Steve Comstock The Trainer's Friend, Inc. 303-355-2752 http://www.trainersfriend.com * To get a good Return on your Investment, first make an investment! + Training your people is an excellent investment * Try our tool for calculating your Return On Investment for training dollars at http://www.trainersfriend.com/ROI/roi.html
