+ else
+ {
+ strcpy (scratchFileName, options.out_name);
+ }
+
+ if (!(asmFile = fopen (scratchFileName, "w")))
+ {
+ werror (E_FILE_OPEN_ERR, scratchFileName);
+ exit (1);
+ }
+
+ /* initial comments */
+ initialComments (asmFile);
+
+ /* print module name */
+ tfprintf (asmFile, "\t!module\n", moduleName);
+ tfprintf (asmFile, "\t!fileprelude\n");
+
+ /* Let the port generate any global directives, etc. */
+ if (port->genAssemblerPreamble)
+ {
+ port->genAssemblerPreamble (asmFile);
+ }
+
+ /* print the global variables in this module */
+ printPublics (asmFile);
+ if (port->assembler.externGlobal)
+ printExterns (asmFile);
+
+ /* copy the sfr segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function registers\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfr->oFile);
+
+ /* copy the sbit segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function bits \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, sfrbit->oFile);
+
+ /* copy the data segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; internal ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, data->oFile);
+
+
+ /* create the overlay segments */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; overlayable items in internal ram \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, ovrFile);
+
+ /* create the stack segment MOF */
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; Stack segment in internal ram \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "\t.area\tSSEG\t(DATA)\n"
+ "__start__stack:\n\t.ds\t1\n\n");
+ }
+
+ /* create the idata segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; indirectly addressable internal ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, idata->oFile);
+
+ /* copy the bit segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; bit data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, bit->oFile);
+
+ /* if external stack then reserve space of it */
+ if (mainf && mainf->fbody && options.useXstack)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external stack \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "\t.area XSEG (XDATA)\n"); /* MOF */
+ fprintf (asmFile, "\t.ds 256\n");
+ }
+
+
+ /* copy xtern ram data */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, xdata->oFile);
+
+ /* copy the interrupt vector table */
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; interrupt vector \n");
+ fprintf (asmFile, "%s", iComments2);
+ copyFile (asmFile, vFile);
+ }
+
+ /* copy global & static initialisations */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; global & static initialisations\n");
+ fprintf (asmFile, "%s", iComments2);
+
+ /* Everywhere we generate a reference to the static_name area,
+ * (which is currently only here), we immediately follow it with a
+ * definition of the post_static_name area. This guarantees that
+ * the post_static_name area will immediately follow the static_name
+ * area.
+ */
+ tfprintf (asmFile, "\t!area\n", port->mem.static_name); /* MOF */
+ tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
+ tfprintf (asmFile, "\t!area\n", port->mem.static_name);
+
+ if (mainf && mainf->fbody)
+ {
+ fprintf (asmFile, "__sdcc_gsinit_startup:\n");
+ /* if external stack is specified then the
+ higher order byte of the xdatalocation is
+ going into P2 and the lower order going into
+ spx */
+ if (options.useXstack)
+ {
+ fprintf (asmFile, "\tmov\tP2,#0x%02x\n",
+ (((unsigned int) options.xdata_loc) >> 8) & 0xff);
+ fprintf (asmFile, "\tmov\t_spx,#0x%02x\n",
+ (unsigned int) options.xdata_loc & 0xff);
+ }
+
+ /* initialise the stack pointer */
+ /* if the user specified a value then use it */
+ if (options.stack_loc)
+ fprintf (asmFile, "\tmov\tsp,#%d\n", options.stack_loc);
+ else
+ /* no: we have to compute it */
+ if (!options.stackOnData && maxRegBank <= 3)
+ fprintf (asmFile, "\tmov\tsp,#%d\n", ((maxRegBank + 1) * 8) - 1);
+ else
+ fprintf (asmFile, "\tmov\tsp,#__start__stack\n"); /* MOF */