jeffh@weycord.WEYCO.COM (01/09/88)
A while back someone asked for a dec to hp real number conversion
routine. The following code was written for a s200 running the
pascal workstation. It's in 68000 assembly but the general
concept should be easily understood. Here goes:
* 14 JAN 85 JWH
* REAL_CNV.TEXT
*
*DEC TO HP REAL CONVERSI0N ROUTINE
*
* DEC REAL FORMAT:
*
* ....SIGN BIT
* . .....eight EXPONENT BITS
* . . .....TWELVE MANTISSA BITS
* . . . ... ALWAYS ZERO
* v v v v
* X/MMMMMMM|S/XXXXXXX|00000000|MMMMM000 <- - - - - 32 BITS TOTAL
*
* NOTE: 1) NEGATIVE NUMBERS ARE 2's COMPLEMENTED
* 2) .5<= MANTISSA <1.0
* 3) EXPONENT IS BIASED BY 128
*
***********************************************************************
*********** ^^ DEC HEWLETT-PACKARD vv ***********
***********************************************************************
*
* HEWLETT-PACKARD REAL FORMAT:
*
* ..SIGN BIT
* . .....ELEVEN EXPONENT BITS
* . . .....FIFTY-TWO MANTISSA BITS
* . . .
* v v v
* S/XXXXXXXXXXX/MMMMMMMMMMMMMMMMMMMM/MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*
* NOTE: .
* 1) NEGATIVES ARE NOT 2's COMPLEMENTED .
* 2) 0<=MANTISSA<1.0 .. 64-BITS TOTAL
* 3) EXPONENT IS BIASED BY 1023
* 4) MC->HP REAL=(MANTISSA-.5)*2 & BIASED EXPONENT-1
PAGE
*
*
* CALLING SEQUENCE FROM PASCAL:
*
* R_CNVRT(COUNT,RAW[1],RESULT[1]);
* ^ ^ ^
* . . .
* . . .
* . . ..........ARRAY REAL CONVERTED NUMBERS
* . ...........DATA IN (ARRAY OF INTEGER)
* ..........SHORTINT ( NUMBER OF REALS TO CONVERT )
*
*------------------------------------------------
MNAME MREALCNVRT
SRC MODULE Mrealcnvrt;
SRC EXPORT
src PROCEDURE R_cnvrt(ANYVAR cnt,raw,result : INTEGER);
SRC END;
DEF Mrealcnvrt_R_cnvrt
DEF Mrealcnvrt_Mrealcnvrt
RORG 0
************************************************************************
* REGISTER ASSIGNMENT: *
* D0=dec REAL *
* D1=COPY OF dec REAL *
* D2,D3=HP REAL *
************************************************************************
MREALCNVRT_R_CNVRT NOP
MOVEA.L 4(SP),A0 ^result array
MOVEA.L 12(SP),A1 ^loop count
MOVE.W (A1),D4 Fetch loop counter
SUB.W #1,D4 DBRA counts to -1
MOVEA.L 8(SP),A1 ^raw array
CLR.L D3 CLEAR RESULT REGISTER 2
loop MOVE.L (A1)+,D0 fetch one DEC real
CLR.L D2 CLEAR RESULT REGISTER 2
MOVE.L D0,D1 COPY DEC REAL
BTST #23,D0 X/MMMMMMM|S/XXXXXXX|00000000|MMMMM000
BEQ PLUS WAS SIGN BIT PLUS OR MINUS
MINUS BSET #31,D2 SET RESULT SIGN BIT TO MINUS
* v CLEAR EXP
PLUS AND.L #$7F000000,D0 0/MMMMMMM0000/00000000000000000000
LSR.L #8,D0 0/00000000000/MMMMMMM0000000000000
LSR.L #3,D0 0/00000000000/MMMMMMM0000000000000
OR.L D0,D2 SET 7 BITS OF MANTISSA IN RESULT
MOVE.L D1,D0 X/MMMMMMMSXXX/XXXX00000000MMMMM000
AND.L #$000000F8,D0 0/00000000000/000000000000MMMMM000
LSL.L #5,D0 0/00000000000/0000000MMMMM00000000
OR.L D0,D2 SET 5 BITS OF MANTISSA IN RESULT
MOVE.L D1,D0 X/MMMMMMMSXXX/XXXX00000000MMMMM000
AND.L #$007F0000,D0 0/00000000XXX/XXXX0000000000000000
LSL.L #5,D0 0/000XXXXXXX0/00000000000000000000
BTST #31,D1 X/MMMMMMM|S/XXXXXXX|00000000|MMMMM000
BEQ NOT_SET WAS LSB OF EXP SET
BSET #20,D0
NOT_SET ADD.L #$37E00000,D0 ADD HP BIAS-(MC BIAS)
OR.L D0,D2 SET EXPONENT IN RESULT
nxt_one MOVE.L D2,(A0)+ push ms words in result
MOVE.L D3,(A0)+ push ls words in result
DBRA D4,LOOP
MOVEA.L (SP)+,A0 pop return addr
ADDA.L #12,SP pop call stack
JMP (A0) RETURN
*------------------------------------------------
MREALCNVRT_MREALCNVRT RTS INITIALIZATION BODY
END
dsmith@hplabsb.UUCP (David Smith) (01/12/88)
In article <400008@weycord.WEYCO.COM>, jeffh@weycord.WEYCO.COM writes: > * DEC REAL FORMAT: > * > * ....SIGN BIT > * . .....eight EXPONENT BITS > * . . .....TWELVE MANTISSA BITS > * . . . ... ALWAYS ZERO > * v v v v > * X/MMMMMMM|S/XXXXXXX|00000000|MMMMM000 <- - - - - 32 BITS TOTAL > * > * NOTE: 1) NEGATIVE NUMBERS ARE 2's COMPLEMENTED > * 2) .5<= MANTISSA <1.0 > * 3) EXPONENT IS BIASED BY 128 Dec Vax/Pdp-11 32 bit float format is like HP's (IEEE's), exept for byte ordering. There are no "always zero" bits. Negative numbers are not 2's complemented, but have their sign bits set. The high-order (2^-1) mantissa bit is not stored. David Smith
jeffh@hpubvwa.HP.COM (Jeff Harrell) (01/14/88)
Yes, you are correct. The low order bits are NOT clear! The code I provided was based on an instrument that did not use the low bits! However, the the rest is CORRECT we've used it for several data transfers and it works! Maybe we are talking about more than the byte order... Give me a call if you have any questions. Jeff ( the guy that wants DIL ) Harrell (206) 924-6142
jeffh@hpubvwa.HP.COM (Jeff Harrell) (01/14/88)
Yes, you are correct. The low order bits are NOT clear! The code I provided was based on an instrument that did not use the low bits! The complement comment was a leftover from ModComp conversion code. Again, the routine was written for the Pascal workstation which does not support 32 bit floats. Jeff ( the guy that wants DIL ) Harrell (206) 924-6142