[comp.lang.asm370] Writing double word binary numbers on screen

SYSADM4@TREARN.BITNET (Suleyman Nazif Kutlu) (09/25/90)

Hi 370 Assemblers..
I have a double word binary number, and I want to write it on screen in
decimal form. How can I write it ? Any help would be appreciated.
 -Suleyman Kutlu
System Programmer

SEB1525@ccfvx3.draper.COM ("Steve Bacher ", Batchman) (09/25/90)

>Hi 370 Assemblers..
>I have a double word binary number, and I want to write it on screen in
>decimal form. How can I write it ? Any help would be appreciated.
> -Suleyman Kutlu
>System Programmer

Try this...

*
* Some code to take the contents of a binary doubleword and convert
* to decimal display format.
*
* This code works for non-negative numbers only.
*
         LM    R4,R5,DBLWORD        Load double word integer
         LTR   R4,R4                If number is negative
         BM    ...                  (sorry, I haven't done this path)
         D     R4,=F'1000000000'    Divide double-int by 10^9
*
* We know that the quotient cannot be greater than 2147483647, so
* a program check is not possible.
*                                   R4 = remainder
*                                   R5 = quotient
         CVD   R5,CVDAREA           Convert quotient to decimal
         UNPK  DSPAREA(9),CVDAREA   Get 9 digits of decimal number
         OI    DSPAREA+8,X'F0'      Fix up sign
         CVD   R4,CVDAREA           Convert remainder to decimal
         UNPK  DSPAREA+9(9),CVDAREA Get 9 digits of decimal number
         OI    DSPAREA+9+8,X'F0'    Fix up sign
*
* Now the dumped integer is at DSPAREA.
* We have 18 digits.  Now get rid of leading blanks.
*
         LA    R1,DSPAREA          Start pointer at start of digits
         LA    R15,17              Set loop count
DLZLOOP  CLI   0(R1),C'0'          Loop until nonzero digit found
         BNE   DLZEND              or last digit found
         MVI   0(R1),C' '          Blank out each leading zero
         LA    R1,1(,R1)           bumping R1 each time
         BCT   R15,DLZLOOP
DLZEND   DS    0H                  R15 contains # of significant
*                                  decimal digits, R1 points to num
         B     FINISHED
         ...
DBLWORD  DS    D                   Here's where your number lives
DSPAREA  DS    CL18                Here's where you put the display
CVDAREA  DS    D                   Conversion work area
         ...


I hope this helps.  Although this code is a slightly-edited extract of a
working double-precision-float display routine that works, I have not
actually tested this excerpt.  Good luck!

				- Steve Bacher
				- Charles Stark Draper Laboratory

XMAS@BOGECNVE.BITNET (09/26/90)

>Hi 370 Assemblers..

Who, me? ;->

>I have a double word binary number, and I want to write it on screen in
>decimal form. How can I write it ? Any help would be appreciated.
> -Suleyman Kutlu
>System Programmer

Try the following code fragment:

* R3 contains the doubleword binary number
*
          CVD   R3,PAKNUM              Convert to decimal
          UNPK  DECNUM,PAKNUM          Unpack to character
          OI    LASTDIG,X'F0'          'Fix' last digit to positive
...
          DS    0D
PAKNUM    DC    CL8                    Packed decimal
DECNUM    DS    0CL15
          DC    CL14                   Unpacked decimal
LASTDIG   DC    CL1                    Last digit
...

I hope this helps.  Of course you should check out the above code with
your compiler.  ;-)

 ... Mark

VALDIS@VTVM1.CC.VT.EDU (Valdis Kletnieks) (09/26/90)

On Tue, 25 Sep 90 14:46:03 -0500 <XMAS%BOGECNVE.BITNET@OHSTVMA.IRCC.OHIO-STATE.E
>* R3 contains the doubleword binary number
Must be some S/390 exetension that allows a 32-bit register to hold a 64-bit
quantity. :-)

Note that a 64-bit signed quantity can be as high as 9,233,372,036,854,775,808.

We can pretend that a 64-bit signed quantity is really equal to
(high4byte * 2**32) + low4byte.

So, closer to reality would be:

            LM   R2,R3,BIT64
            CVD  R2,FIELD1
            CVD  R3,FIELD2
            MP   FIELD1,OFF32   (OFF32 is a packed decimal form of 2**32)
            AP   FIELD1(..),FIELD2(..)
            UNPK FIELD1,PRINTABLE

You'll have to actually do the MP and AP in several stages, since it can
only do 15 digits at a time, and you'll have to handle 20 digits.

Cheat sheet:  Back in elementary school, you probably did stuff like:

       1234
      X  56
     ------
       7404
      6170.
     ------
      69104

Remember to keep track of the sign on the low 4 bytes.. ;)


                                  Valdis Kletnieks
                                  Computer Systems Engineer
                                  Virginia Polytechnic Institute