Roberto Jose Etcheverry Romero

[HC08 CW] LDHX is converted to a series of ops

Discussion created by Roberto Jose Etcheverry Romero on Jun 11, 2008
Latest reply on Jun 19, 2008 by Roberto Jose Etcheverry Romero
Since the HC08 cpu has a 16 by 8 div function and the CW compiler isnt smart enough to use it and instead uses _IDIVU_8, i was trying to use __ASM to load the 3 bytes, do a DIV and save the result, the problem is that when i disassemble the __ASM part it gives me this:
  154:    __asm{
  155:          LDHX    kmh_constant:1
  0019 ce0001   [4]             LDX   kmh_constant:1
  001c 89       [2]             PSHX 
  001d 8a       [2]             PULH 
  001e ce0002   [4]             LDX   kmh_constant:2
  156:          LDA     kmh_constant
  0021 c60000   [4]             LDA   kmh_constant
  157:          LDX     kmhtimer
  0024 ce0000   [4]             LDX   kmhtimer
  158:          STA     kmh
  0027 c70000   [4]             STA   kmh
  159:    }
why it likes to replace my LDHX with a full load of the word kmh_constant, i dont know, if i understand the asm sintaxis correctly, kmh_constant:1 refers to the highest order byte of the 2, so i'm loading the high byte in the high part of the X register, and the compiler tries to load a 3rd byte which i think would crash the uC because there is no 3rd byte to kmh_constant...
How do i force the compiler to use MY instruction and not what it thinks is correct?

Outcomes