I want to write an assembly version of this function:
uint16_t intel16_asm( uint16_t value);
Looking at the assembly generated for a C version of that function, it would appear that return address is passed in H:X, the parameter is on the stack (SP+1 holds MSB, SP+2 holds LSB) and the return is expected in H:X. So, I came up with the following assembly to swap the byte order:
PSHX ; push return addressPSHH LDHX 4, SP ; load LSB of parameter to H, junk to XLDX 3, SP ; load MSB of parameter to XRTS ; return
So what syntax should I use to create this function? Can I mark it as inline and have the compiler inline the assembly so it loads a 16-bit value into H:X and then does the PSHH PSHX PULH PULX sequence to swap the byte order?
I tried doing:
uint16_t intel16_asm( uint16_t value){ asm { PSHH PSHX PULH PULX RTS }}But then I get a warning because the function doesn't return. Is it even safe to use RTS in the assembly? If I take the RTS out, how do I indicate to the compiler that the return value is already loaded in H:X? How do I tell the compiler not to push the return address for me?
If I want to write the 32-bit version of this function, I assume a 32-bit parameter is passed on the stack in a similar fashion? How is a 32-bit return value passed out?
Finally, any recommended tutorials or references for learning HC08 assembly? I did HC11 over 18 years ago, and don't remember anything about it. I've been doing a lot of Rabbit assembly (originally based on Z80 instruction set) over the past 10 years, and so far the HC08 syntax has been very foreign to me.
-Tom
(HC08 with CodeWarrior 5.9.0)