| ??? 06/07/07 15:14 Modified: 06/07/07 15:16 Read: times |
#140377 - Division / modulus not always slow Responding to: ???'s previous message |
Bob said:
Some discussion, though: division and modulus operations take a nice chunk of code, even with precompiled libraries and unsigned integers. Ooh. You can't assume such things. Here's the code generated by my 8051 C compiler for a simple test:
321 void test() {
\ 023E test:
322
323 unsigned char a, b, c;
324
325 a = b / c;
\ 023E 7800 MOV R0,#$LOCBI test+1
\ 0240 E6 MOV A,@R0
\ 0241 7800 MOV R0,#$LOCBI test+2
\ 0243 86F0 MOV B,@R0
\ 0245 84 DIV AB
\ 0246 7800 MOV R0,#$LOCBI test
\ 0248 F6 MOV @R0,A
326 a = b % c;
\ 0249 7800 MOV R0,#$LOCBI test+1
\ 024B E6 MOV A,@R0
\ 024C 7800 MOV R0,#$LOCBI test+2
\ 024E 86F0 MOV B,@R0
\ 0250 84 DIV AB
\ 0251 E5F0 MOV A,B
\ 0253 7800 MOV R0,#$LOCBI test
\ 0255 F6 MOV @R0,A
327
328 }
\ 0256 22 RET
329
Your mileage may vary with a different compiler and/or a processor that doesn't have a divide instruction. It also gets worse on an 8-bit CPU if the variables are wider than 8 bits.
-- Russ |
| Topic | Author | Date |
| Software design problem | 01/01/70 00:00 | |
| Something like this, maybe? | 01/01/70 00:00 | |
| Well, yes, actually... | 01/01/70 00:00 | |
| Duhr and a question | 01/01/70 00:00 | |
| Which ones did you look at ? | 01/01/70 00:00 | |
| Duhr and an answer | 01/01/70 00:00 | |
| Is it not possible to | 01/01/70 00:00 | |
| Horses for courses | 01/01/70 00:00 | |
| have fun | 01/01/70 00:00 | |
| A Queue? | 01/01/70 00:00 | |
| I used what I called a \'cache\' | 01/01/70 00:00 | |
| Gah, code repost | 01/01/70 00:00 | |
| you need to read it all, THEN process | 01/01/70 00:00 | |
| Your approach is much more general... | 01/01/70 00:00 | |
| Prioritizing? | 01/01/70 00:00 | |
| Some suggestions Bob | 01/01/70 00:00 | |
| Thank you, sir! | 01/01/70 00:00 | |
| Division / modulus not always slow | 01/01/70 00:00 | |
| Are we making this too difficult? | 01/01/70 00:00 | |
I don't think so, it seems to work pretty well... | 01/01/70 00:00 |



