variable in inline assembly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

variable in inline assembly

3,783件の閲覧回数
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.
ラベル(1)
タグ(1)
0 件の賞賛
返信
3 返答(返信)

599件の閲覧回数
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 件の賞賛
返信

599件の閲覧回数
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 件の賞賛
返信

599件の閲覧回数
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 件の賞賛
返信