资源描述:
《avr汇编百例 - 浮点程序库》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、;范例62.ORG$A00EXCH:MOVR5,R8;两浮点数交换子程序MOVR8,R12MOVR12,R5EXCH1:MOVR5,R9;尾数交换MOVR9,R13MOVR13,R5MOVR5,R10;双字节交换MOVR10,R14MOVR14,R5MOVR5,R11MOVR11,R15MOVR15,R5RETDP:ANDIR16,$7F;处理积/商数符,计算积/商阶码子程序SBRCR9,7SUBIR16,$80SBRCR13,7SUBIR16,$80;积/商符号放在r16,7ADDR12,R8;移码相加(除数阶码已求补)LDIR17,$80
2、BRCCDP1ADDR12,R17;移码求和有进位,将和再加上$80,再有进位为溢出RETDP1:SUBR12,R17;移码求和无进位,将和减去$80,有借位RET;或差为0也为溢出NEG3:COMR15;3字节数据求补COMR14;先求反后加1COMR13INC3:LDIR17,255SUBR15,R17;以减去-1代替加1SBCR14,R17SBCR13,R17RET;范例63;浮点数比较大小子程序X1为被减数X2为减数FPCP:SBRCR9,7;X1为正,跳行RJMPCP1SBRCR13,7;X2为正,跳行RJMPCP2;X1,X2异号
3、FPCP1:CPR11,R15;X1,X2皆为正,以尾数低位字节,中位字节,高位字节和CPCR10,R14;阶码的顺序(按无符号数)进行比较CPCR9,R13;不等,阶码大者浮点数值也大;只有阶码和尾数对应相等,CPCR8,R12;两浮点数才相等RET;比较结果:Z=1时X1=X2,否则C=0时X1>X2,C=1时X14、R10;阶码的顺序(按无符号数)进行比较CPCR13,R9;但要将X1、X2交换位置后按正数比较过程进行CPCR12,R8CP4:RET;比较结果:Z=1时X1=X2,否则C=0时X1>X2,C=1时X15、N1:RETFPLAD:ANDIR16,$3f;清除被加数,加数数符SBRCR9,7ORIR16,$80;被加数数符取到(R16,7)SBRCR13,7ORIR16,$40;加数数符取到(R16,6)LDIR17,$80ORR9,R17ORR13,R17;恢复尾数最高位MOVR17,R12SUBR17,R8;计算阶差BREQGOON;两阶相等,转BRCCNX3NEGR17;不够减求补CPIR17,24BRCCEXAD;
6、阶差
7、>24,取被加数为和NX2A:LSRR13RORR14RORR15DECR17BRNENX2A;加数阶小,右移加数对阶
8、MOVR12,R8;取被加数阶为和之阶BRCCGOONRCALLINC3;舍入移出位RJMPGOONNX3:CPIR17,24BRCCCOM1;阶差>24,取加数为和LOOP:LSRR9RORR10RORR11DECR17BRNELOOP;加数阶大,右移被加数对阶BRCCGOONRCALLINC3A;舍入移出位GOON:SBRCR16,6SUBIR16,$80SBRSR16,7;判别两数是否同号RJMPSAMS;同号转SUBR15,R11;异号,执行减法,加数为被减数SBCR14,R10SBCR13,R9BRCCNOM;够减转SUBIR16,
9、$40;否则被减数数符求反为和之数符RCALLNEG3;并将差求补NOM:MOVR17,R13ORR17,R14ORR17,R15BREQDON0;差为0转NMLOP:SBRCR13,7RJMPCOM1LSLR15ROLR14ROLR13DECR12BRNENMLOP;规格化OV1:SEV;阶码变为0,下溢(可取为0,不算溢出)RETSAMS:ADDR15,R11ADCR14,R10ADCR13,R9;两数同号,执行加法BRCCCOM1RORR13RORR14RORR15INCR12;有进位时右规1次($7F+1=$80溢出)BREQOV1;
10、阶码增1后变为0为上溢BRNCCOM1RCALLINC3COM1:CLVSBRCR16,6RETCOMA:LDIR17,$7FANDR13,R17;正数数符为0DO