Menu

#2946 sdasstm8 bugs

open
nobody
None
other
5
2020-06-05
2019-11-18
Picatout
No

the sdasstm8 assembler code is in error for the following 2 instructions:
div x,y code 0x62 instead of 0x65
jrxx . (conditonnal jump to istself) give a relative address short of 1 byte. It jump after the 0x90 prefix. It is ok for no prefix jrxx instructions.

Discussion

  • Philipp Klaus Krause

    I just tested a small sample program using current SDCC. div x, y is assembled to 0x62, just as the STM8 CPU programming manual says it should.

     
    • Picatout

      Picatout - 2020-06-05

      DIV X,Y is not a valid instruction and should trigger an error message. The valid instruction is DIVW X,Y with opcode 0x65. opcode 0x62 is for DIV X,A

       
  • Philipp Klaus Krause

    Regarding jrh, etc: These actually seem wrong according to the STM8 CPU programming manual. However, before changing it in the assembler, I'd like to see this verified on real hardware (the 2-byte jrxx instructions add the 2 to the pc before addign the offset, so what about these 0x90-prefixed 3-byte jrxx? Do they also add 2, like the manual says, or 3, like the assembler assumes??

     

    Last edit: Philipp Klaus Krause 2020-04-29
    • Eric Rullens

      Eric Rullens - 2020-06-05

      Using the assembler in the STVP tool, it looks like the 0x90-prefixed opcodes add 3.

      0x8000 | 0x2706 | JREQ 0x8008
      

      So 0x8000 + 2 + 6 = 0x8008.

      0x8010 | 0x902905 | JRH 0x8018
      

      So 0x8010 + 3 + 5 = 0x8018.

      And an example for a conditional "jump to self":

      0x8020 | 0x9029FD | JRH 0x8020
      

      So 0x8020 + 3 - 3 = 0x8020.

      The PM0044 Rev 2 manual says on JRxx:

      Syntax:
      JRxx dst
      
      Operation:
      PC = PC+lgth
      PC <= PC + dst, if Condition is True
      

      In the instruction list lgth is listed as 2 or 3 depending on the 0x90 prefix.

      Funnily enough, for the JRH instruction used in the example above, the manual shows a 0x29 opcode in the overview list. But 0x29 is the JRV instruction in the same list. The specific table in the JRxx section lists JRH correctly as 0x90 0x29.

       
    • Picatout

      Picatout - 2020-06-05
      ASxxxx Assembler V02.00 + NoICE + SDCC mods  (STMicroelectronics STM8), page 2.
      Hexadecimal [24-Bits]
      
      
      
                                           56         ;ld a, #0x80
                                           57         ;ld WWDG_CR,a ; WWDG_CR used to reset mcu
                                           58     ;iret
                                           59 
                                 0017FF    60 STACK=0x17ff 
            000001                         61 main:
                                           62 ; initialize SP
            000001 AE 17 FF         [ 2]   63         LDW     X,#STACK  ;initialize return stack
            000004 94               [ 1]   64         LDW     SP,X
            000005 90 29 FE         [ 1]   65         JRH     .
            000008 20 FE            [ 2]   66         JRA     . 
      

      For the instruction JRH . it should be 90 29 FD as it is it jump to 29 which is JRV

       

Log in to post a comment.

Auth0 Logo