;/*=============================================================== =============*/;/* Copyright (C 2004 YINXING TECHNOLOGY CO., LTD */;/* All Rights Reserved. */;/* ----------------------------------------------------------------------------*/;/*=============================================================== =============*/;---------------------------------------------------------------;; USER Program Demo !; It Start At 0x1800,and interrupt vector don't changed,; At 200h !;; Please Don't modify PMST !;; Some data put in 080h DP=1; SP may use system stack,so user needn't setup SP !;;------------------------------------------------------------------.title "for test user program ... ".mmregs.global _c_int00.ref fs_start,errnoop1valh .set 4140h ;floating point number 12.0op1vall .set 0000hop2valh .set 4140h ;floating point number 12.0op2vall .set 0000hinitst0 .set 1800h ;set st0 initial numberinitst1 .set 2900h ;set st1 initial number.bss rlthm,1 ;result high mantissa,address is 80h .bss rltlm,1 ;result low mantissa,address is 81h.bss rltsign,1 ;ressult sigh,address is 82h.bss rltexp,1 ;result exponent,address is 83h.bss op1hm,1 ;op1 high mantissa,address is 84h.bss op1lm,1 ;op1 low mantissa,address is 85h.bss op1se,1 ;op1 sigh and exp,address is 86h.bss op2se,1 ;op2 sigh and exponent,address is 87h .bss op2hm,1 ;op2 high mantissa,address is 88h.bss op2lm,1 ;op2 low mantissa,address is 89h.bss op1_hsw,1 ;op1 packed high,address is 8ah .bss op1_lsw,1 ;op1 packed low,address is 8bh.bss op2_hsw,1 ;op2 packed high,address is 8ch .bss op2_lsw,1 ;op2 packed low,address is 8dh_c_int00:stm #initst0,st0stm #initst1,st1rsbx C16ld #op1lm,dpld #op1valh,a ;load float numberstl a,op1_hswld #op1vall,astl a,op1_lswld #op2valh,a ;load float numberstl a,op2_hswld #op2vall,astl a,op2_lswnopnopnop ;1st breakpoint in CCS!;----------- conversion of floating point format - unpack ------- dld op1_hsw,a ;load OP1 to acc asfta a,8sfta a,-8bc op1_zero,AEQ ;if op1 is 0,jump to special casesth a,-7,op1se ;store sign and exponent to stackstl a,op1lm ;store low mantissaand #07Fh,16,a ;mask off sign and exp to get high mantissa add #080h,16,a ;add implied 1 to mantissasth a,op1hm ;store mantissa to stackdld op2_hsw,a ;load OP2 to acc asfta a,8sfta a,-8bc op2_zero,AEQ ;if op2 is 0,jump to special casesth a,-7,op2se ;store sign and exponent to stackstl a,op2lm ;store low mantissaand #07Fh,16,a ;mask off sign and exp to get high mantissa add #080h,16,a ;add implied 1 to mantissasth a,op2hm ;store mantissa to stacknopnopnop ;2nd breakpoint in CCS !;---------- judge the sign----------------bitf op1se,#100h ;test the sign bitbc testop2,NTC ;if is not negative jump to testop2ld #0,a ;change the experssion todsub op1hm,adst a,op1hm ;store changed op1testop2:bitf op2se,#100h ;test the sign bitbc compexp,NTC ;if is not negative jump to compexpld #0,a ;change the expression todsub op2hm,adst a,op2hm ;store changed op2;--------- Exponent Comparison ------------compexp:ld op1se,aand #00ffh,a ;mask off the sign bitld op2se,band #00ffh,b ;mask off the sign bitsub a,b ;exp op2-exp op1 -> bbc op1_gt_op2,BLT ;process op1 > op2bc op2_gt_op1,BGT ;process op2 > op1a_eq_bdld op1hm,adadd op2hm,a ;add mantissabc res_zero,AEQ ;if result is zero process special caseld op1se,b ;load exponent in preparation for normalizing normalizesth a,rltsign ;Save signed mantissa on stackabs a ;Create magnitude value of mantissasftl a,6 ;Pre–normalize adjustment of mantissaexp a ;Get amount to adjust exp for normalizationnorm a ;Normalize the resultst t,rltexp ;Store exp adjustment valueadd #1,b ;Increment exp to account for implied carrysub rltexp,b ;Adjust exponent to account for normalization normalizedstl b,rltexp ;Save result exponent on stackbc underflow,BLEQ ;process underflow if occurssub #0ffh,b ;adjust to check for overflowbc overflow,BGEQ ;process overflow if occurssftl a,-7 ;Shift right to place mantissa for splittingstl a,rltlm ;Store low mantissaand #07f00h,8,a ;Eliminate implied onesth a,rlthm ;Save result mantissa on stack;----------- Conversion of Floating Point Format- Pack --------- ld rltsign,9,aand #100h,16,a ;Get the sign valueadd rltexp,16,a ;Add the result exponent togethersftl a,7 ;shift the value to right placedadd rlthm,a ;Add the result mantissa togetherreturn_valuenopnopnopnop ; 3th breakpoint in CCS !b fs_startop1_gt_op2abs b ;if exp OP1 >= exp OP2 + 24 then return OP1sub #24,bbc return_op1,BGEQadd #23,b ;restore exponent difference valuestl b,rltsign ;store exponent difference to be used as RPCdld op2hm,a ;load OP2 mantissarpt rltsign ;normalize OP2 to match OP1sfta a,-1bd normalize ;delayed branch to normalize resultld op1se,b ;load exponentvalue to prep for normalization dadd op1hm,a ;add OP1 to OP2op2_gt_op1sub #24,b ;if exp OP2 >= exp OP1 + 24 then return OP1 bc return_op2,BGEQadd #23,b ;Restore exponent difference valuestl b,rltsign ;Store exponent difference to be used as RPC dld op1hm,a ;Load OP1 mantissarpt rltsign ;Normalize OP1 to match OP2sfta a,-1bd normalize ;Delayed branch to normalize resultld op2se,b ;Load exponent value to prep for normalization dadd op2hm,a ;Add OP2 to OP1op1_zero:return_op2:bd return_valuedld op2_hsw,a ;Put OP2 as result into Aop2_zero:return_op1:dld op1hm,a ;Load signed high mantissa of OP1bc op1_pos,AGT ;If mantissa is negative .neg a ;Negate it to make it a positive valueaddm #100h,op1se ;Place the sign value back into op1_se op1_possub #80h,16,a ;Eliminate implied one from mantissald op1se,16,b ;Put OP1 back together in acc A as a result bd return_valuesftl b,7add b,aoverflowst #2,errno ;load error nold rltsign,16,a ;pack sign of result and #8000,16,aor #0ffffh,a ;result low mantissa bd return_valueadd #07f7fh,16,a ;result exponent underflowst #1,errno ;load error nob return_valueres_zerobd return_valuesub a,anop。