Need help from Assembler Freaks

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks,

I have a new problem. I have a programm for IAR Compiler which has also some inline assembler.

Now, I'm porting the application to gcc.
When compiling I get several Errors on the inline assembler code. And I got stuck in how to solve this problem.

  
      //   R31 stuck test
__asm("R31_0x55_TST:                              \n"
      "               ldi  R31, $55               \n"
      "               cpi  R31, $55               \n"
      "               breq  R31_0xAA_TST          \n"  
      "               jmp  Failure                \n"
      "R31_0xAA_TST:  ldi  R31, $AA               \n"
      "               cpi  R31, $AA               \n"
      "               breq  R30_0x55_TST          \n"  
      "               jmp  Failure                \n"
);

      //   R30 stuck test
__asm("R30_0x55_TST:  ldi  R30, $55               \n"
      "               cpi  R30, $55               \n"
      "               breq  R30_0xAA_TST          \n"  
      "               jmp  Failure                \n"
      "R30_0xAA_TST:  ldi  R30, $AA               \n"
      "               cpi  R30, $AA               \n"
      "               breq  R28_0x55_TST          \n"
      "               jmp  Failure                \n"
);

      //   R29 stuck test
__asm("R29_0x55_TST:  mov R31, R29     ; save R29 \n"    
      "                ldi  R29, $55              \n"    
      "               cpi  R29, $55               \n"
      "               breq  R29_0xAA_TST          \n"
      "               jmp  Failure                \n"
      "R29_0xAA_TST:  ldi  R29, $AA               \n"
      "               cpi  R29, $AA               \n"
      "               breq  R29_END_TST           \n"  
      "               jmp  Failure                \n"
      "R29_END_TST:   mov R29, R31  ; restore R29 \n" 
);

      //   R28 stuck test
__asm("R28_0x55_TST:  mov R31, R28     ; save R28 \n"
      "               ldi  R28, $55               \n"
      "               cpi  R28, $55               \n"
      "               breq  R28_0xAA_TST          \n"  
      "               jmp  Failure                \n"
      "R28_0xAA_TST:  ldi  R28, $AA               \n"
      "               cpi  R28, $AA               \n"
      "               breq  R28_END_TST           \n"  
      "               jmp  Failure                \n"
      "R28_END_TST:   mov R28, R31  ; restore R28 \n"    
);


      //   R27 stuck test
__asm("R27_0x55_TST:                              \n"
      "               ldi  R27, $55               \n"
      "               cpi  R27, $55               \n"
      "               breq  R27_0xAA_TST          \n"  
      "               jmp  Failure                \n"
      "R27_0xAA_TST:  ldi  R27, $AA               \n"
      "               cpi  R27, $AA               \n"
      "               breq  R27_END_TST           \n"  
      "               jmp  Failure                \n"
      "R27_END_TST:                               \n"    
);


      // R0 to R27 stuck test
__asm("RX_TST:        ldi  R30,$00                \n"
      "               ldi  R31,$00                \n"
      "RX_0x55_TST:   ldi  R27,$55                \n"
      "               st  Z,R27                   \n"
      "               ldi  R27,$00                \n"
      "               ld  R27,Z                   \n"
      "               cpi  R27,$55                \n"
      "               breq  RX_0xAA_TST           \n"
      "               jmp  Failure                \n"
      "RX_0xAA_TST:   ldi  R27,$AA                \n"
      "               ST  Z,R27                   \n"
      "               ldi  R27,$00                \n"
      "               ld  R27,Z+                  \n"
      "               cpi  R27, $AA               \n"
      "               breq  RX_TST_2              \n"
      "               jmp  Failure                \n"
      "RX_TST_2:      cpi  r30,27 ; test until R27 \n"
      "               brne  RX_0x55_TST           \n"
);

  // Stack pointer Stuck Test (16 bit Stack pointer)
  // Save SP values
__asm("SP_TST:        in    R23,$3E               \n"
      "               in    R22,$3D               \n"
      "SPL_0x55_TST:  ldi   R24,$55               \n"
      "               out   $3D,R24               \n"
      "               in    R24,$3D               \n"
      "               cpi   R24,$55               \n"
      "               breq  SPL_0xAA_TST          \n"
      "               jmp   Failure               \n"
      "SPL_0xAA_TST:  ldi   R24,$AA               \n"
      "               out   $3D,R24               \n"
      "               in    R24,$3D               \n"
      "               cpi   R24,$AA               \n"
      "               breq  SPH_0x55_TST          \n"
      "               jmp   Failure               \n"
      "SPH_0x55_TST:  ldi   R25,"SPH_MASK
      "               andi  R25,$55               \n"
      "               out   $3E,R25               \n"
      "               in    R24,$3E               \n"
      "               cp    R24,R25               \n"
      "               breq  SPH_0xAA_TST          \n"
      "               jmp   Failure               \n"
      "SPH_0xAA_TST:  ldi   R25,"SPH_MASK
      "               andi  R25,$AA               \n"
      "               out   $3E,R25               \n"
      "               in    R24,$3E               \n"
      "               cp    R24,R25               \n"
      "               breq  RESTORE_SP            \n"
      "               jmp   Failure               \n"
      "RESTORE_SP:    out   $3E,R23               \n"
      "               out   $3D,R22               \n"
      "               rjmp  ALL_TEST_OK           \n"
);


     // stop here on failure
     // replace by an exit if necessary
__asm("Failure:        jmp   Failure              \n"
      "ALL_TEST_OK:                               \n"
);

The Output is as follow:

C:\TEMP/ccT3QD3k.s:27: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:28: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:31: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:32: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:37: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:38: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:41: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:42: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:48: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:49: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:52: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:53: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:60: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:61: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:64: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:65: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:72: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:73: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:76: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:77: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:83: Error: junk at end of line, first unrecognized character is `0'
C:\TEMP/ccT3QD3k.s:84: Error: junk at end of line, first unrecognized character is `0'
C:\TEMP/ccT3QD3k.s:85: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:87: Error: junk at end of line, first unrecognized character is `0'
C:\TEMP/ccT3QD3k.s:89: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:92: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:94: Error: junk at end of line, first unrecognized character is `0'
C:\TEMP/ccT3QD3k.s:96: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:103: Error: constant value required
C:\TEMP/ccT3QD3k.s:103: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:104: Error: constant value required
C:\TEMP/ccT3QD3k.s:104: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:105: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:106: Error: constant value required
C:\TEMP/ccT3QD3k.s:106: Error: `,' required
C:\TEMP/ccT3QD3k.s:106: Error: garbage at end of line
C:\TEMP/ccT3QD3k.s:106: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:107: Error: constant value required
C:\TEMP/ccT3QD3k.s:107: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:108: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:111: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:112: Error: constant value required
C:\TEMP/ccT3QD3k.s:112: Error: `,' required
C:\TEMP/ccT3QD3k.s:112: Error: garbage at end of line
C:\TEMP/ccT3QD3k.s:112: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:113: Error: constant value required
C:\TEMP/ccT3QD3k.s:113: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:114: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:118: Error: junk at end of line, first unrecognized character is `5'
C:\TEMP/ccT3QD3k.s:119: Error: constant value required
C:\TEMP/ccT3QD3k.s:119: Error: `,' required
C:\TEMP/ccT3QD3k.s:119: Error: garbage at end of line
C:\TEMP/ccT3QD3k.s:119: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:120: Error: constant value required
C:\TEMP/ccT3QD3k.s:120: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:125: Error: unknown opcode `aa'
C:\TEMP/ccT3QD3k.s:126: Error: constant value required
C:\TEMP/ccT3QD3k.s:126: Error: `,' required
C:\TEMP/ccT3QD3k.s:126: Error: garbage at end of line
t unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:127: Error: constant value required
C:\TEMP/ccT3QD3k.s:127: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:131: Error: constant value required
C:\TEMP/ccT3QD3k.s:131: Error: `,' required
C:\TEMP/ccT3QD3k.s:131: Error: garbage at end of line
C:\TEMP/ccT3QD3k.s:131: Error: junk at end of line, first unrecognized character is `3'
C:\TEMP/ccT3QD3k.s:132: Error: constant value required
C:\TEMP/ccT3QD3k.s:132: Error: `,' required
C:\TEMP/ccT3QD3k.s:132: Error: garbage at end of line
C:\TEMP/ccT3QD3k.s:132: Error: junk at end of line, first unrecognized character is `3'

So, what I found out, that I cannot find anything about the $ sign in gcc assembler manual. Maybe it is not used in gcc. But what to put there then? Just delete the $ ?
If I do so, the result is as follow:

C:\TEMP/ccRKN1BX.s: Assembler messages:
C:\TEMP/ccRKN1BX.s:103: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:104: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:106: Error: `,' required
C:\TEMP/ccRKN1BX.s:106: Error: constant value required
C:\TEMP/ccRKN1BX.s:106: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:107: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:112: Error: `,' required
C:\TEMP/ccRKN1BX.s:112: Error: constant value required
C:\TEMP/ccRKN1BX.s:112: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:113: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:119: Error: `,' required
C:\TEMP/ccRKN1BX.s:119: Error: constant value required
C:\TEMP/ccRKN1BX.s:119: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:120: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:126: Error: `,' required
C:\TEMP/ccRKN1BX.s:126: Error: constant value required
C:\TEMP/ccRKN1BX.s:126: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:127: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:131: Error: `,' required
C:\TEMP/ccRKN1BX.s:131: Error: constant value required
C:\TEMP/ccRKN1BX.s:131: Error: garbage at end of line
C:\TEMP/ccRKN1BX.s:132: Error: `,' required
C:\TEMP/ccRKN1BX.s:132: Error: constant value required
C:\TEMP/ccRKN1BX.s:132: Error: garbage at end of line

And what about the strange C:\TEMP/ccRKN1BX.s filename? How can I find that file? It is not in TEMP. Is it deleted right after compiling?

Thanks in advance.
Baldrian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The standard prefix for hex constants is "0x" not "$"

But wouldn't you be better off taking this into a .S file rather than battling with the obscure inline syntax?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The standard prefix for hex constants is "0x" not "$"

But wouldn't you be better off taking this into a .S file rather than battling with the obscure inline syntax?

OK. Changing $ to 0x makes all errors go away.
Why is IAR using a $ instead of 0x? Or is $ in IAR not the same as 0x in gcc and now my code will not do what it is intended to do?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Why is IAR using a $ instead of 0x? Or is $ in IAR not the same as 0x in gcc and now my code will not do what it is intended to do?

Different compilers use different notations. $ and 0x both just tell the compiler that the number is in hexadecimal format. I'm not surprised that it doesn't work as intended. The inline assembler is different and the registers used are probably different for both compilers. As Cliff mentioned it would be easier to make an .S file so you can use straight asm. Either way you will need to have a firm understanding of what the code is trying to accomplish in order to port it correctly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well hex has been done in different ways by different assemblers and compilers over the years, 0xNN just happens to be one way to do it and $NN another. Others include 0NNh and hNN.

But the C programming language uses 0xNN so it kind of makes sense for inline asm in C to also follow this pattern.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK. Than I'm one step further. 0x = $
Nice.

CirMicro wrote:

I'm not surprised that it doesn't work as intended. The inline assembler is different and the registers used are probably different for both compilers. As Cliff mentioned it would be easier to make an .S file so you can use straight asm. Either way you will need to have a firm understanding of what the code is trying to accomplish in order to port it correctly.

Until now, I didn't check if the code works as intended.
I managed to get all compiler errors away. That was my first step. Now I have to study the source to check if it does what I want.

Thanks clawson and thanks CirMicro