Hello Steve,
I suspect that, from the label names you have used, you are attempting to adapt some existing flash programming code, written entirely in assembler, to inline assembly. An alternative approach is to directly calling the assembly routines (within an .asm file), as a C function. The only requirement is that the assembly routines use the same parameter passing convention as C.
I discovered the attached code for a "Standard software SGF driver" (for HCS08 devices), apparently downloaded previously from somewhere on the Freescale website, I can't remember where. The header file shows how the assembly routines are called as C functions. As an example, I will list one of the function prototypes from within the header file.
void Write_Flash(
unsigned char *dest, /* First address to be programmed */
unsigned char length, /* Number of data bytes to be written */
unsigned char *source /* Pointer to start of data buffer */
);
The assembly routine is named Write_Flash, and actually used burst mode to write a number of bytes to flash. The data to be written is contained within a suitable buffer, identified by source.
If you examine the assembly code, you will find the following requirements on entry to the routine -
The first parameter, the destination address is pushed the stack, low byte first, prior to the call.
The second parameter, the data length, is present in the accumulator.
The third parameter, the buffer address, is present in H:X.
The Erase_Page routine has a single destination address parameter, and this is present in H:X.
If you need to alter the number of parameters, and/or their type, there would be differences from the above. However, if you stick with the same parameters, the functions should work, whatever the inner workings of the assembly routines.
Yet another alternative is to provide a "C wrapper" for the assembly routines, where the inputs required by each routine are handled by inline assembler and then the routine is called as a JSR. For example -
Write_Flash_Row(
unsigned char *dest, unsigned char length, unsigned char *source)
{
asm {
ldhx dest
pshx
pshh
lda length
ldhx source
jsr Write_Flash
}
}
Regards,
Mac
Message Edited by bigmac on
2008-02-11 02:01 AM