Hello, and welcome to the forum.
The fact that you are merging two different applications will probably mean that you will need to do more "tinkering" with the code than you might like. You do not mention which HC05 devices were previously used, and the HCS08 device to which you are migrating. Note that the use of macros will not produce more compact code - their one purpose is to make the code more understandable by virtue that a common sequence of instructions can be replaced by a more meaningful label. Do not confuse a macro with a sub-routine.
The most significant enhancements to the later devices would be:
- The ability for the code to directly manipulate the stack, for the purpose of creating temporary variables required by a sub-routine, and
- The index size for the X-indexed addressing modes is now 16 bits, rather than 8 bits, by virtue of the additional H-register. This means that an instruction such as LDA ,X can now fetch from anywhere in the normal addressing range, rather than only page 0 RAM. However, your code will now need to explicitly set the H-register value whenever indexed addressing is utilised.
There are numerous other enhancements, but these would seem to be the most important ones that will reduce the requirements for page 0 RAM, and to provide more efficient code. The adaption of the existing code should attempt to make use of these features.
For the HC05, the stack will occupy the top of page 0 RAM. For the HCS08, the stack pointer should be explicitly initialised to the top of RAM, to maximize the page 0 resource. This is accomplished with the following code. Never use the RSP instruction.
_Startup: LDHX #RAMEnd+1 TXS ; Adjust stack pointer
Whenever the code exceeds a conditional branch limit, consider incorporating some of the intervening code within a separate sub-routine (not a macro). It would seem that some of the original code must have borderline, for this to now occur.
The following generic examples give possible sub-routine frameworks for incorporating local variables on the stack. For the first example, intermediate stack operations within the sub-routine would affect the offset required for a variable, should the stack pointer alter.
VAR1 EQU 1VAR2 EQU 2FUNC1: PSHX ; Save values to stack, as req'd. PSHH PSHA AIS #-2 ; Create space for two 8-bit variables ; Body of sub-routine CLR VAR1,SP LDA #100 STA VAR2,SP LDA 3,SP ; Original ACC value DEC VAR2,SP ; Etc. AIS #2 ; Adjust stack pointer PULA ; Restore prior values PULH PULX RTS
Now a slightly different arrangement that allows intermediate stack operations, without affecting the offset for the variables.
VAR1 EQU 0VAR2 EQU 1FUNC1: PSHX ; Save values to stack, as req'd. PSHH PSHA AIS #-2 ; Create space for two 8-bit variables TSX ; Body of sub-routine CLR VAR1,X LDA #100 STA VAR2,X LDA 2,X ; Original ACC value DEC VAR2,X ; Etc. AIS #2 ; Adjust stack pointer PULA ; Restore prior values PULH PULX RTS
Application note AN1218 HC05 to HC08 Optimization, may provide further explanation of using the enhanced instructions. Additionally there is AN2717 M68HC08 to HCS08 Transition, which describes the differences within the HC05 -> HC08 -> HCS08 migration.
Regards,
Mac