[comp.lang.asm370] hex to decimal

SPGAAC@UCCVMA.BITNET ("Adam Cohen SPGAAC@UCCVMA.UCOP.EDU 987-0346", 415) (02/10/90)

 say you've got a hex value in a register and
 want to convert it to decimal.  isnt there
 a quick way to do this with shifts?

I01BAILE@ETSU.BITNET (Don Bailes) (02/10/90)

The easiest way to convert a hex value in a register to decimal (packed)
form is the CVD instruction.  See IBM 370: Computer Organization and Assembly
Language for a complete discussion of CVD.  If your intention is to print
the number, use ED after the CVD to convert the number to printable form.

NAD100T@ODUVM.BITNET (Tony D'Amato) (02/10/90)

On Fri, 9 Feb 90 12:58:52 EST Adam Cohen SPGAAC@UCCVMA.UCOP.EDU (415)987-0346
said:
> say you've got a hex value in a register and
> want to convert it to decimal.  isnt there
> a quick way to do this with shifts?

I'm not sure what you are asking -- if you want to print it out in
decimal, here's a good way to do it:

         L     R15,NUMBR            Load number
         CVD   R15,DOUBLE           Convert number to packed
         MVC   TEXT,PREFIX          Move edit prefix to buffer
         ED    TEXT,DOUBLE+5        Edit number to prefix
         ....
PREFIX   DS    X'402020202120'
NUMBR    DS    H'123456'            number to convert
DOUBLE   DS    D
TEXT     DS    CL6

At the end, TEXT will contain your decimal number.

I hope this helped...

|========================================================================|
| Tony D'Amato                     |                                     |
| Computer Systems Engineer        | "Deesclaimer! I don't neeed no      |
| Old Dominion University          |  steenkin' deesclaimer!"            |
| E-Mail: NAD100T@ODUVM.BITNET     |                                     |
| -or-    nad100t@oduvm.cc.odu.edu |   -- with apologies to Mel Brooks   |
|========================================================================|

BRUCE@UMDD.BITNET (Bruce Crabill) (02/10/90)

If by hex you mean a binary value, then the following will work (and without
shifts too):

The following code will convert a binary value into a string of EBCDIC
numbers.  The binary value is assumed to be positive.  In any case, the
sign will be ignored.  The value to convert is loaded into R1.  The
result is left in the area labeled DECOUT.  DECTMP is a scratch area
and must be 8 bytes long. DECOUT can be up to 10 bytes long.

         L     R1,<Value>
         CVD   R1,DECTMP
         UNPK  DECOUT,DECTMP
         OI    DECOUT+L'DECOUT-1,X'F0'

DECTMP   DS    D
DECOUT   DS    CL8

                                       Bruce

SOMITCW@VCCSCENT.BITNET (02/10/90)

>say you've got a hex value in a register and
>want to convert it to decimal.  isnt there
>a quick way to do this with shifts?

    If by HEX to DECIMAL, you mean convert a register value to
 a HEX display format, use UNPK and TR.

    Example:

         ST    Rx,WORK1           Put the register in storage for UNPacK
         UNPK  OUTPUT(9),WORK(5)  UNPacK the register's data
         TR    OUTPUT(8),TABLE    Translate X'FA'-X'FF' to C'A'-C'F'
*
OUTPUT   DS    CL8,CL1            Output area for HEX in display format
*
WORK     DS    XL4                Register hold area
*
TABLE    EQU   *-240              TRANSLATE TABLE
         DC    CL16'0123456789ABCDEF'
*

    Notes: The 5th byte of WORK is referenced by UNPK.
           The 9th byte of OUTPUT is garbage.
           The programs base register must point more than 240 bytes
               before where TABLE is defined.