File indexing completed on 2025-05-11 08:23:48
0001 #include "fpsp-namespace.h"
0002 //
0003 //
0004 // binstr.sa 3.3 12/19/90
0005 //
0006 // Description: Converts a 64-bit binary integer to bcd.
0007 //
0008 // Input: 64-bit binary integer in d2:d3, desired length (LEN) in
0009 // d0, and a pointer to start in memory for bcd characters
0010 // in d0. (This pointer must point to byte 4 of the first
0011 // lword of the packed decimal memory string.)
0012 //
0013 // Output: LEN bcd digits representing the 64-bit integer.
0014 //
0015 // Algorithm:
0016 // The 64-bit binary is assumed to have a decimal point before
0017 // bit 63. The fraction is multiplied by 10 using a mul by 2
0018 // shift and a mul by 8 shift. The bits shifted out of the
0019 // msb form a decimal digit. This process is iterated until
0020 // LEN digits are formed.
0021 //
0022 // A1. Init d7 to 1. D7 is the byte digit counter, and if 1, the
0023 // digit formed will be assumed the least significant. This is
0024 // to force the first byte formed to have a 0 in the upper 4 bits.
0025 //
0026 // A2. Beginning of the loop:
0027 // Copy the fraction in d2:d3 to d4:d5.
0028 //
0029 // A3. Multiply the fraction in d2:d3 by 8 using bit-field
0030 // extracts and shifts. The three msbs from d2 will go into
0031 // d1.
0032 //
0033 // A4. Multiply the fraction in d4:d5 by 2 using shifts. The msb
0034 // will be collected by the carry.
0035 //
0036 // A5. Add using the carry the 64-bit quantities in d2:d3 and d4:d5
0037 // into d2:d3. D1 will contain the bcd digit formed.
0038 //
0039 // A6. Test d7. If zero, the digit formed is the ms digit. If non-
0040 // zero, it is the ls digit. Put the digit in its place in the
0041 // upper word of d0. If it is the ls digit, write the word
0042 // from d0 to memory.
0043 //
0044 // A7. Decrement d6 (LEN counter) and repeat the loop until zero.
0045 //
0046 // Implementation Notes:
0047 //
0048 // The registers are used as follows:
0049 //
0050 // d0: LEN counter
0051 // d1: temp used to form the digit
0052 // d2: upper 32-bits of fraction for mul by 8
0053 // d3: lower 32-bits of fraction for mul by 8
0054 // d4: upper 32-bits of fraction for mul by 2
0055 // d5: lower 32-bits of fraction for mul by 2
0056 // d6: temp for bit-field extracts
0057 // d7: byte digit formation word;digit count {0,1}
0058 // a0: pointer into memory for packed bcd string formation
0059 //
0060
0061 // Copyright (C) Motorola, Inc. 1990
0062 // All Rights Reserved
0063 //
0064 // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
0065 // The copyright notice above does not evidence any
0066 // actual or intended publication of such source code.
0067
0068 //BINSTR idnt 2,1 | Motorola 040 Floating Point Software Package
0069
0070 |section 8
0071
0072 #include "fpsp.defs"
0073
0074 .global binstr
0075 binstr:
0076 moveml %d0-%d7,-(%a7)
0077 //
0078 // A1: Init d7
0079 //
0080 moveql #1,%d7 //init d7 for second digit
0081 subql #1,%d0 //for dbf d0 would have LEN+1 passes
0082 //
0083 // A2. Copy d2:d3 to d4:d5. Start loop.
0084 //
0085 loop:
0086 movel %d2,%d4 //copy the fraction before muls
0087 movel %d3,%d5 //to d4:d5
0088 //
0089 // A3. Multiply d2:d3 by 8; extract msbs into d1.
0090 //
0091 bfextu %d2{#0:#3},%d1 //copy 3 msbs of d2 into d1
0092 asll #3,%d2 //shift d2 left by 3 places
0093 bfextu %d3{#0:#3},%d6 //copy 3 msbs of d3 into d6
0094 asll #3,%d3 //shift d3 left by 3 places
0095 orl %d6,%d2 //or in msbs from d3 into d2
0096 //
0097 // A4. Multiply d4:d5 by 2; add carry out to d1.
0098 //
0099 asll #1,%d5 //mul d5 by 2
0100 roxll #1,%d4 //mul d4 by 2
0101 swap %d6 //put 0 in d6 lower word
0102 addxw %d6,%d1 //add in extend from mul by 2
0103 //
0104 // A5. Add mul by 8 to mul by 2. D1 contains the digit formed.
0105 //
0106 addl %d5,%d3 //add lower 32 bits
0107 nop //ERRATA ; FIX #13 (Rev. 1.2 6/6/90)
0108 addxl %d4,%d2 //add with extend upper 32 bits
0109 nop //ERRATA ; FIX #13 (Rev. 1.2 6/6/90)
0110 addxw %d6,%d1 //add in extend from add to d1
0111 swap %d6 //with d6 = 0; put 0 in upper word
0112 //
0113 // A6. Test d7 and branch.
0114 //
0115 tstw %d7 //if zero, store digit & to loop
0116 beqs first_d //if non-zero, form byte & write
0117 sec_d:
0118 swap %d7 //bring first digit to word d7b
0119 aslw #4,%d7 //first digit in upper 4 bits d7b
0120 addw %d1,%d7 //add in ls digit to d7b
0121 moveb %d7,(%a0)+ //store d7b byte in memory
0122 swap %d7 //put LEN counter in word d7a
0123 clrw %d7 //set d7a to signal no digits done
0124 dbf %d0,loop //do loop some more!
0125 bras end_bstr //finished, so exit
0126 first_d:
0127 swap %d7 //put digit word in d7b
0128 movew %d1,%d7 //put new digit in d7b
0129 swap %d7 //put LEN counter in word d7a
0130 addqw #1,%d7 //set d7a to signal first digit done
0131 dbf %d0,loop //do loop some more!
0132 swap %d7 //put last digit in string
0133 lslw #4,%d7 //move it to upper 4 bits
0134 moveb %d7,(%a0)+ //store it in memory string
0135 //
0136 // Clean up and return with result in fp0.
0137 //
0138 end_bstr:
0139 moveml (%a7)+,%d0-%d7
0140 rts
0141 |end