This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

在C语言中添加汇编

Other Parts Discussed in Thread: AM1808

大神们,帮忙啊,菜鸟一只,刚接触汇编。我这边想在C语言中添加汇编模块,汇编模块的作用是对GPIO口进行拉高拉低,即输出一个方波。但在编译的时候汇编部分出现如下错误:

  ERRORS:

       [E0001] Illegal symbol

        [E0003] Unexpected trailing operand(s)

       [E0200] Bad term in expression

经过检查发现,出问题是下面两条汇编语句

    LDR r0,=0x01E2606c

    STR r1,[r0]

 我就是想对控制GPIO的相应寄存器进行赋值。请问一下

1 上述汇编有没有问题,因为我发现像mov等关键字都会变颜色,但LDR和STR没有变。感觉好像不支持一样(我用的是CCS v4,芯片是AM1808)

2 ccsv4支持的汇编语句及其相应的例子可以在哪里看

3 C语言和汇编混合编程有什么资料推荐吗

  • 写法不对,参考文档spru187t的7.5.4节:

    7.5.4 Using Inline Assembly Language
    Within a C/C++ program, you can use the asm statement to insert a single line of assembly language into
    the assembly language file created by the compiler. A series of asm statements places sequential lines of
    assembly language into the compiler output with no intervening code. For more information, see
    Section 6.8.
    The asm statement is useful for inserting comments in the compiler output. Simply start the assembly
    code string with a semicolon (;) as shown below:
    asm(";*** this is an assembly language comment");
    NOTE: Using the asm Statement
    Keep the following in mind when using the asm statement:
    • Be extremely careful not to disrupt the C/C++ environment. The compiler does not check
    or analyze the inserted instructions.
    • Avoid inserting jumps or labels into C/C++ code because they can produce
    unpredictable results by confusing the register-tracking algorithms that the code
    generator uses.
    • Do not change the value of a C/C++ variable when using an asm statement. This is
    because the compiler does not verify such statements. They are inserted as is into the
    assembly code, and potentially can cause problems if you are not sure of their effect.
    • Do not use the asm statement to insert assembler directives that change the assembly
    environment.
    • Avoid creating assembly macros in C code and compiling with the --symdebug:dwarf (or
    -g) option. The C environment’s debug information and the assembly macro expansion
    are not compatible.