??? 03/25/04 04:54 Read: times |
#67396 - RE: hex to decimal assembly Responding to: ???'s previous message |
I think Graham was talking about the process of dealing with numbers in the 10 to 15 digits size wherein it is not feasible to "just stuff them into registers". As such the conversion becomes also one of buffer management. And sometimes on a smaller processor that is already strapped for resources the results of a conversion may be going directly to a UART or LCD screen and it can be convenient to have them in most significant digit first order.
I have often made a conversion routine that is supported in a loop that iterates for the number of digits in the number and then uses a table as the source for the divisors. For example if I am working with 32-bit fixed point numbers and want to convert I will provide a 32 by 32 divide routine and then setup a loop to do successive divides using a table like: ; #pragma SRC ; ; ; unsigned long code Dec_Divisors[]= ; {1000000000L, ; 100000000L, ; 10000000L, ; 1000000L, ; 100000L, ; 10000L, ; 1000L, ; 100L, ; 10L, ; 1L}; ; Dec_Divisors: DB 03BH,09AH,0CAH,000H ; long 1000000000 DB 005H,0F5H,0E1H,000H ; long 100000000 DB 000H,098H,096H,080H ; long 10000000 DB 000H,00FH,042H,040H ; long 1000000 DB 000H,001H,086H,0A0H ; long 100000 DB 000H,000H,027H,010H ; long 10000 DB 000H,000H,003H,0E8H ; long 1000 DB 000H,000H,000H,064H ; long 100 DB 000H,000H,000H,00AH ; long 10 DB 000H,000H,000H,001H ; long 1 Forgive me for deriving the table using Keil C51 to translate the constants. It is unfortunate that the typical 8051 assembler, Keil included, does not provide for a "DD" directive to define storage for 32-bit constants. If you write your iteration loop properly it is possible to omit the last divide by 1 without even having to make a special case of the last iteration handling if you arrange the final remainder to be the same storage place as you pick the digits from. It is possible to make a large number conversion more efficient too by dropping back to a 16x16 divide after five or six iterations of the loop. (ie just watch for the high word going to zero). Michael Karas |
Topic | Author | Date |
hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
Back to basics | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
RE: hex to decimal assembly | 01/01/70 00:00 | |
Forgot a few stuff, continuing on... | 01/01/70 00:00 | |
Number representations | 01/01/70 00:00 | |
Erm... Another correction to myself![]() | 01/01/70 00:00 |