assemblyarmcortex-marmcc

How to perform DCD in C using __asm?


I am trying to do the ASM instruction DCD 0xf7f0a000 in ARM C code.

The below methods I tried and errors I got:

__asm("DCD 0xf7f0a000");

Error : #3061: unrecognized instruction opcode

__asm
{
MOV r0,=0xf7f0a000
MOV r1,{r0}
}

Error: Implicit physical register R0 should be defined as a variable.

Error: Implicit physical register R1 should be defined as a variable.

Update:

ARM Compiler Version: ARM Compiler 5.06 update 6

PS: I am trying to generate an exception by doing undefined operation.


Solution

  • ARMCC has very good quality documentation available from the vendor.

    You did not specify the version of your ARMCC, apparently things have changed since I used it (~15 years ago).

    You need to study this if you want to use inline assembly (again - if this fits your compiler version): https://developer.arm.com/tools-and-software/software-development-tools/legacy-tools/ds-5-development-studio/resources/tutorials/using-inline-assembly-to-improve-code-efficiency

    Note: Register names in inline assembly code are treated as C or C++ variables. They do not necessarily relate to the physical register of the same name. In our C code, we use the variable names r5 and r6 for our operands, but the actual registers used are r1 and r2.

    Inline __asm can be very cumbersome to use unless you perfectly understand what you're doing. It is usually much easier to place your assembly code into a separate file. (Used to have .asm extension back then, not sure about now).

    PS: I am trying to generate an exception by doing undefined operation.

    As far as I can see, you are trying to write into invalid address, this is not the same as 'undefined operation' and you can do this from C using an invalid pointer, no need for asm at all:

    int *a;
    a = 0xf7f0a000;
    *a = 2019;
    

    Another edit: And finally answering the actual question in the title :) I don't think you can. DCD is not an opcode, it is an assembler directive, it can't be used within __asm block (inline assembly), it can only be used in the 'real' assembly language code.