When including a div operation in a calculation the generated code size increases dramatically (in terms of memory generally available on an embedded target). It appears that the compiler uses generic software math routines from the rtl/inc folder (generic.inc and int64.inc). These routines includes an error check (HandleErrorAddrFrameInd) which pulls in a bunch of code (get_caller_frame, pushexceptionobject, dounhandledexception, raiseexception etc.).
I've adapted (formerly) Atmel's application note AVR200 div routines to fpc to get a comparison between fpc's build-in code and an alternative approach without exception handling (see attached demo program). I've compiled the example withppcrossavr -Tembedded -Wpatmega328p -Cpavr5 -Pavr -O3 -g -a -al -XPavr-
Compiling attached example with build-in div :
67 lines compiled, 0.1 sec, 2630 bytes code, 310 bytes data
Compiling attached example with custom div function:
67 lines compiled, 0.1 sec, 290 bytes code, 0 bytes data
1st question - is exception handling code required (by language convention) on embedded targets?
2nd question - is there a need for more compact math routines for the AVR embedded target?