1: ldfps = 170100^tst 2: stfps = 170200^tst 3: / ftoa -- basic g fp conversion 4: 5: .globl _ndigit 6: .globl ecvt 7: .globl fcvt 8: 9: 10: / ecvt converts fr0 into decimal 11: / the string of converted digits is pointed to by r0. 12: / the number of digits are specified by _ndigit 13: / r2 contains the decimal point 14: / r1 contains the sign 15: 16: .globl _ecvt, _fcvt 17: 18: _ecvt: 19: mov r5,-(sp) 20: mov sp,r5 21: mov r2,-(sp) 22: movf 4(r5),fr0 23: mov 14(r5),_ndigit 24: jsr pc,ecvt 25: br 1f 26: 27: _fcvt: 28: mov r5,-(sp) 29: mov sp,r5 30: mov r2,-(sp) 31: movf 4(r5),fr0 32: mov 14(r5),_ndigit 33: jsr pc,fcvt 34: 1: 35: mov r2,*16(r5) 36: mov r1,*20(r5) 37: mov (sp)+,r2 38: mov (sp)+,r5 39: rts pc 40: 41: fcvt: 42: clr eflag 43: br 1f 44: ecvt: 45: mov $1,eflag 46: 1: 47: stfps -(sp) 48: ldfps $200 49: movf fr0,-(sp) 50: movf fr1,-(sp) 51: mov r3,-(sp) 52: mov $buf,r1 53: clr r2 54: clr sign 55: tstf fr0 56: cfcc 57: beq zer 58: bgt 1f 59: inc sign 60: negf fr0 61: 1: 62: modf $one,fr0 63: tstf fr1 64: cfcc 65: beq lss 66: 67: gtr: 68: movf fr0,-(sp) 69: movf fr1,fr0 70: 1: 71: mov $buftop,r3 72: 1: 73: modf tenth,fr0 74: movf fr0,fr2 75: movf fr1,fr0 76: addf $epsilon,fr2 77: modf $ten,fr2 78: movfi fr3,r0 79: add $'0,r0 80: movb r0,-(r3) 81: inc r2 82: tstf fr0 83: cfcc 84: bne 1b 85: / 86: mov $buf,r1 87: 1: 88: movb (r3)+,(r1)+ 89: cmp r3,$buftop 90: blo 1b 91: / 92: movf (sp)+,fr0 93: br pad 94: 95: zer: 96: inc r2 97: br pad 98: 99: lss: 100: dec r2 101: modf $ten,fr0 102: tstf fr1 103: cfcc 104: beq lss 105: inc r2 106: jsr pc,digit1 107: 108: pad: 109: jsr pc,digit 110: br out 111: br pad 112: 113: digit: 114: cmp r1,$buftop 115: bhis 1f 116: add $2,(sp) 117: modf $ten,fr0 118: 119: digit1: 120: movfi fr1,r0 121: add $'0,r0 122: movb r0,(r1)+ 123: 1: 124: rts pc 125: / 126: out: 127: mov $buf,r0 128: add _ndigit,r0 129: tst eflag 130: bne 1f 131: add r2,r0 132: 1: 133: cmp r0,$buf 134: blo outout 135: movb (r0),r3 136: add $5,r3 137: movb r3,(r0) 138: 1: 139: cmpb (r0),$'9 140: ble 1f 141: movb $'0,(r0) 142: cmp r0,$buf 143: blos 2f 144: incb -(r0) 145: br 1b 146: 2: 147: movb $'1,(r0) 148: inc r2 149: 1: 150: outout: 151: mov sign,r1 152: mov _ndigit,r0 153: tst eflag 154: bne 1f 155: add r2,r0 156: 1: 157: clrb buf(r0) 158: mov $buf,r0 159: mov (sp)+,r3 160: movf (sp)+,fr1 161: movf (sp)+,fr0 162: ldfps (sp)+ 163: rts pc 164: 165: epsilon = 037114 166: one = 40200 167: ten = 41040 168: .data 169: tenth: 037314; 146314; 146314; 146315 170: _ndigit:10. 171: .bss 172: buf: .=.+40. 173: buftop: 174: sign: .=.+2 175: eflag: .=.+2 176: .text