variable in inline assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

variable in inline assembly

3,515 Views
brenda
Contributor I
hi, I'm using CodeWarrior 6.3 for a ColdFire v2 MCU. I defined constant expression  in inline assembly like this: asm
          { msg: dc.b "hello\n"
             .............
          } 
when running, a window shows" Exception vector name: Address Error PC where the exception happend:0x20000528.
I have check the Inline Assembly Chapter in ColdFire_Build_Tools_Reference.pdf. it's allowed to define like this in inline assembly, is there sth wrong with it or do I need to include some special headerfiles? Thanks.
Labels (1)
0 Kudos
3 Replies

331 Views
CompilerGuru
NXP Employee
NXP Employee
How do you use this dc.b? Of course you must make sure the CPU does not try to execute the "hello\n". Can you show a complete sample?
Also sizeof("hello\n") is 7, not sure if you have to align the end of such byte directives in inline assembly (actually not even sure if this dc.b emits 6 or 7 bytes).

Daniel
0 Kudos

331 Views
brenda
Contributor I
For example, if I wanna find the position of the first letter "e" in "hello"
main()
{    int i=0;
     asm
      { x1: dc.b  "hello\n"
        lea x1,a3
        
       search: move.b (a3),d1
                    cmp #0x65,d1
                    beq find
                    cmp #0x0a,d1
                    beq end
                    add #0x1,a3
                    bra search
       find:      move.l a3,i
                    bra end
       end:
       }
}
 
when running step by step to x1: dc.b...... the above error appears, it seems the CPU try to excute it resulted in an error, but there are similar examples in CodeWarrior Build Tools Reference on page 192.  Thanks
0 Kudos

331 Views
CompilerGuru
NXP Employee
NXP Employee
When you write the dc.b like this then the output of the hello will be executed as binary commands.
Only a disassembler knows what that executes :smileyhappy:.
Actually I did not see any sample of dc.b in the CF 6.3 version of ColdFire_Build_Tools_Reference.pdf,
however the Targeting_ColdFire.pdf has a snippet. Whille that snippet comes in the form of a function, it is not meant to be executed ever, it only shows how the syntax works and as you saw, the syntax is accepted by the compiler.

When you work on (inline) assembly level, then you are responsible that the CPU gets to execute legal instructions. In the case of a dc.b with a string, this means you have to place it somewhere the CPU never actually executes code.

Daniel

PS: Is this a homework assignment? If not, use strchr to find the first 'e' in a string in C :smileyhappy:.

0 Kudos