1: / 2: / 3: 4: / rc -- complex arithmetic 5: 6: .globl c8c16 7: .globl c16c8 8: .globl i4c8 9: .globl r4c8 10: .globl r8c8 11: .globl i4c16 12: .globl r4c16 13: .globl r8c16 14: .globl cad8 15: .globl csb8 16: .globl cmp8 17: .globl cdv8 18: .globl cng8 19: .globl cad16 20: .globl csb16 21: .globl cmp16 22: .globl cdv16 23: .globl cng16 24: .globl rval16 25: .globl rval16p 26: .globl gas16 27: .globl ceq8 28: .globl cne8 29: .globl ceq16 30: .globl cne16 31: 32: .globl cpi8 33: .globl cpi16 34: 35: one = 040200 36: a = r2 37: b = r3 38: c = r4 39: d = r5 40: 41: e = r0 42: f = r1 43: 44: gas16: 45: mov 16.(sp),r0 46: setd 47: movf (sp)+,a 48: movf (sp)+,b 49: tst (sp)+ 50: movf a,(r0)+ 51: movf b,(r0)+ 52: jmp *(r4)+ 53: 54: rval16p: 55: mov r3,r0 56: add (r4)+,r0 57: mov (r0),r0 58: br 1f 59: 60: rval16: 61: mov (r4)+,r0 62: 1: 63: setd 64: movf (r0)+,a 65: movf (r0)+,b 66: movf b,-(sp) 67: movf a,-(sp) 68: jmp *(r4)+ 69: 70: cad16: 71: setd 72: br 1f 73: 74: cad8: 75: setf 76: 1: 77: jsr pc,garg 78: addf a,e 79: addf b,f 80: br sarg 81: 82: csb16: 83: setd 84: br 1f 85: 86: csb8: 87: setf 88: 1: 89: jsr pc,garg 90: subf a,e 91: negf e 92: subf b,f 93: negf f 94: br sarg 95: 96: cmp16: 97: setd 98: br 1f 99: 100: cmp8: 101: setf 102: 1: 103: jsr pc,garg 104: mulf a,e 105: mulf b,f 106: subf f,e 107: mulf d,a 108: mulf c,b 109: movf a,f 110: addf b,f 111: 112: sarg: 113: movf f,-(sp) 114: movf e,-(sp) 115: jmp *(r4)+ 116: 117: cdv16: 118: setd 119: br 1f 120: 121: cdv8: 122: setf 123: 1: 124: divide: 125: jsr pc,garg 126: absf e 127: absf f 128: cmpf e,f 129: cfcc 130: blt 1f 131: 132: / algorithm #1 |c| > |d| 133: 134: movf d,e 135: divf c,e / r = d/c 136: movf d,f 137: mulf e,f 138: addf c,f / x = c+rd 139: movf f,c 140: movf a,f 141: mulf e,f 142: negf f 143: addf b,f 144: mulf b,e 145: addf a,e 146: divf c,e 147: divf c,f 148: br sarg 149: 150: / algorithm #2 |c| < |d| 151: 152: 1: 153: movf c,e 154: divf d,e / r = c/d 155: movf c,f 156: mulf e,f 157: addf d,f / x = d+rc 158: movf f,c 159: movf b,f 160: mulf e,f 161: subf a,f 162: mulf a,e 163: addf b,e 164: divf c,e 165: divf c,f 166: br sarg 167: 168: cng16: 169: setd 170: br 1f 171: 172: cng8: 173: setf 174: 1: 175: movf (sp)+,a 176: negf a 177: negf (sp) 178: movf a,-(sp) 179: jmp *(r4)+ 180: 181: / setup the following registers 182: / (a,bi) +o (c,di) -> (e+fi) 183: / a,b,c,d are input 184: / e,f are output and also contain 185: / c,d on input 186: 187: garg: 188: mov (sp)+,r0 189: movf (sp)+,e 190: movf e,c 191: movf (sp)+,f 192: movf f,d 193: movf (sp)+,a 194: movf (sp)+,b 195: jmp (r0) 196: 197: i4c8: 198: setf 199: br 1f 200: 201: i4c16: 202: setd 203: 1: 204: setl 205: movif (sp)+,fr0 206: br 2f 207: 208: r4c8: 209: setf 210: br 1f 211: 212: r8c16: 213: setd 214: 1: 215: movf (sp)+,fr0 216: br 2f 217: 218: r4c16: 219: setd 220: br 1f 221: 222: r8c8: 223: setf 224: 1: 225: movof (sp)+,fr0 226: 2: 227: clrf -(sp) 228: movf fr0,-(sp) 229: jmp *(r4)+ 230: 231: c16c8: 232: setd 233: br 1f 234: 235: c8c16: 236: setf 237: 1: 238: movf (sp)+,r0 239: movf (sp)+,r1 240: movfo r1,-(sp) 241: movfo r0,-(sp) 242: jmp *(r4)+ 243: 244: ceq16: 245: setd 246: br 1f 247: ceq8: 248: setf 249: 1: 250: mov $1,r1 251: br 2f 252: 253: cne16: 254: setd 255: br 1f 256: 257: cne8: 258: setf 259: 1: 260: clr r1 261: 2: 262: jsr pc,garg 263: cmpf c,a 264: cfcc 265: bne 1f 266: cmpf d,b 267: cfcc 268: beq 2f 269: 1: 270: inc r1 271: bic $2,r1 272: 2: 273: mov r1,-(sp) 274: jmp *(r4)+ 275: 276: cpi8: 277: setf 278: br 1f 279: 280: cpi16: 281: setd 282: 1: 283: clr r0 284: tst (sp)+ 285: mov (sp)+,r1 286: bge 1f 287: inc r0 288: neg r1 289: 1: 290: movf (sp)+,fr0 291: movf fr0,fr4 292: movf (sp)+,fr0 293: movf fr0,fr5 294: movf $one,fr0 295: clrf fr1 296: 1: 297: dec r1 298: bmi 1f 299: movf fr0,fr2 300: movf fr1,fr3 301: mulf fr4,fr0 302: mulf fr4,fr1 303: mulf fr5,fr2 304: mulf fr5,fr3 305: subf fr3,fr0 306: addf fr2,fr1 307: br 1b 308: 1: 309: tst r0 310: beq 1f 311: clrf -(sp) 312: movf $one,fr2 313: movf fr2,-(sp) 314: movf fr1,-(sp) 315: movf fr0,-(sp) 316: jmp divide 317: 1: 318: movf fr1,-(sp) 319: movf fr0,-(sp) 320: jmp *(r4)+