>>>>> "Lotfi" == nospam <Lotfi> writes:Lotfi> the best routine :-)) to extract the numbers Lotfi> int m,c,d,u; Lotfi> int Magic, s; Lotfi> double Val; Lotfi> // floor 16 bits Lotfi> unsigned short ns=Val; // here the entry point Lotfi> int W=16; Lotfi> m=0; c=0; d=0; u=0; Lotfi> if (ns>32767) {printf("Attention n�gatif "); Lotfi> ns=-ns; } Lotfi> Magic=8389; s=7; // d=1000 Lotfi> m=floor((Magic*ns>>W)>>s); Lotfi> // if (m>10) alors d�passement affichage Lotfi> ns-=1000*m; Lotfi> Magic=5243; s=3; // d=100 Lotfi> c=floor((Magic*ns>>W)>>s); Lotfi> ns-=100*c; Lotfi> Magic=52429; s=3; // d=10 Lotfi> d=floor((Magic*ns>>W)>>s); Lotfi> u=ns-10*d; I believe these magic numbers might be wrong, since the assumption was that all the numbers would fit in a signed 16-bit integer. 52429 clearly doesn't fit. I think they should be d m s 1000 -31981 9 100 5243 3 10 26215 2 A negative m means that instead of computing m*n/2^W, we compute m*n/2^W + n. Ray
convert hex to dec four digits on 320F24x DSP
Started by ●May 24, 2004
Reply by ●May 27, 20042004-05-27
Reply by ●May 27, 20042004-05-27
>>>>> "Jerry" == Jerry Avins <jya@ieee.org> writes:Jerry> Lotfi wrote: Jerry> ... >> f(M,s)= M/2^s/2^16 - 1/d Jerry> M/2^s/2^16 = (M/2^s)/2^16 = M/2^(s+16). Is that what you mean? I think so. But in the book, the computation is done like m*n/2^W/2^s because on many processors the product is returned in 2 registers, so m*n/2^W is just the register containing the most significant W bits of the result. For a DSP that has a single register containing the product, your result would work very nicely. Ray
Reply by ●May 28, 20042004-05-28
"Raymond Toy" <toy@rtp.ericsson.se> a �crit dans le message news: sxdpt8qc6e2.fsf@edgedsp4.rtp.ericsson.se...> >>>>> "Jerry" == Jerry Avins <jya@ieee.org> writes: > > Jerry> Lotfi wrote: > > Jerry> ... > > >> f(M,s)= M/2^s/2^16 - 1/d > > Jerry> M/2^s/2^16 = (M/2^s)/2^16 = M/2^(s+16). Is that what you mean? > > I think so. But in the book, the computation is done like m*n/2^W/2^s > because on many processors the product is returned in 2 registers, so > m*n/2^W is just the register containing the most significant W bits of > the result. > > For a DSP that has a single register containing the product, your > result would work very nicely. > > Rayof course, I have 2 words for product results my routine is : but there is a mistake somewhere, coz I don't see the correct result :-( I am in the debugging process :-) ; Convertit un "Word" hexa en "4 chars D�cimaux + signe" ConvDec .macro Var LACC Var BCND positif?, GEQ ZAC SUB Var SACL Var LACC #02Bh B evitneg? positif? LACC #02Dh evitneg? SACL *+ ; SPM 0 ;PM=00, no shift after multiplication ; Magic=8389; s=7; // d=1000 ; m=floor((Magic*ns>>W)>>s); LT M8389 MPY Var SPH tmp LACC tmp,9 ;16-7=9 SACH tmp ;ie 7 LSR ; ici on aurait du checker le d�passement de m>9! ; ns-=1000*m; LACC Var LT tmp MPY #1000 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL *+ ; ecrit char : millier ; Magic=5243; s=3; // d=100 ; c=floor((Magic*ns>>W)>>s); LT M5243 MPY Var SPH tmp LACC tmp,13 ;16-3=13 SACH tmp ;ie 3 LSR ; ns-=100*c; LACC Var LT tmp MPY #100 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL *+ ; ecrit char : centaine ; Magic=52429; s=3; // d=10 ; d=floor((Magic*ns>>W)>>s); LT M52429 MPY Var SPH tmp LACC tmp,13 ;16-3=13 SACH tmp ;ie 3 LSR ; ns-=10*m = u LACC Var LT tmp MPY #10 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL *+ ; ecrit char : dizaine LACC Var ADD #030h ; table de charact�res : chiffres SACL *+ ; ecrit char : unit� .endm
Reply by ●June 1, 20042004-06-01
solved the errors, the right code is : and it works fine :-) ; Convertit un "Word" hexa en "4 chars D�cimaux + signe" ConvDec .macro Var LACC Var BCND positif?, GEQ ZAC SUB Var SACL Var LACC #02Dh B evitneg? positif? LACC #02Bh evitneg? SACL signe CLRC SXM ; pas de sign extension ; SPM 0 ;PM=00, no shift after multiplication ; Magic=8389; s=7; // d=1000 ; m=floor((Magic*ns>>W)>>s); LT M8389 MPY Var SPH tmp LACC tmp,9 ;16-7=9 SACH tmp ;ie 7 LSR ; ici on aurait du checker le d�passement de m>9! ; ns-=1000*m; LACC Var LT tmp MPY #1000 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL millier ; ecrit char : millier ; Magic=5243; s=3; // d=100 ; c=floor((Magic*ns>>W)>>s); LT M5243 MPY Var SPH tmp LACC tmp,13 ;16-3=13 SACH tmp ;ie 3 LSR ; ns-=100*c; LACC Var LT tmp MPY #100 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL centaine ; ecrit char : centaine ; Magic=52429; s=3; // d=10 ; d=floor((Magic*ns>>W)>>s); LT M52429 MPYU Var ;MPY unsigned SPH tmp LACC tmp,13 ;16-3=13 SACH tmp ;ie 3 LSR ; ns-=10*m = u LACC Var LT tmp MPY #10 SPAC ;Subtract PREG from ACC SACL Var LACC tmp ADD #030h ; table de charact�res : chiffres SACL dizaine ; ecrit char : dizaine LACC Var ADD #030h ; table de charact�res : chiffres SACL unite ; ecrit char : unit� SETC SXM ; remet le sign extension .endm with .bss Var,1 .bss signe,1 .bss millier,1 .bss centaine,1 .bss dizaine,1 .bss unite,1 .bss M8389,1 .bss M5243,1 .bss M52429,1 .bss M5000,1 and initialisation LDP #M8389 SPLK #8389, M8389 SPLK #5243, M5243 SPLK #52429, M52429 SPLK #5000, M5000