This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Mixing C and assembly

I have written one code in the assembly language for mixing C and assembly. The compiler is not properly generating the code for one instruction. I have written the following code,

LDR r0,[pc, #74]

here I want to load a word value from the PC+offset. Here I want the 16 bit LDR instruction should be used by the compiler. But compiler is taking LDR.W instruction, which is general instruction for +/- offset and which is 32 bit. But I want to instruct the compiler for the usage of the 16 bit instructions, how to do this?
Also if I want to use the LDR.W instruction I will write the same, but why the compiler is generating a different instruction, although syntax of both instruction is different?

Parents
  • Code is as follows,

    void assemblytestcode(void)
    {
            __asm
            {
                      LDR    r0,[pc,#74]
                      LDRSB  r0,[r0,#0x00]
                      LDR    r1,[pc,#74]
                      STR    r0,[r1,#0x00]
            }
    
    
    }
    
    

    and the assembly viewed in the simulation is as follows,

        42:         __asm
        43:         {
    0x00005000 B510      PUSH     {r4,lr}
        44:                   LDR       r0,[pc,#74]
    0x00005002 F8DF004A  LDR.W    r0,[pc,#74]  ; @0x00005050
        45:                   LDRSB  r0,[r0,#0x00]
    0x00005006 F9900000  LDRSB    r0,[r0,#0x00]
        46:                   LDR       r1,[pc,#74]
    0x0000500A F8DF104A  LDR.W    r1,[pc,#74]  ; @0x00005058
        47:                         STR    r0,[r1,#0x00]
        48:         }
        49:
        50:
    0x0000500E 6008      STR      r0,[r1,#0x00]
    

Reply
  • Code is as follows,

    void assemblytestcode(void)
    {
            __asm
            {
                      LDR    r0,[pc,#74]
                      LDRSB  r0,[r0,#0x00]
                      LDR    r1,[pc,#74]
                      STR    r0,[r1,#0x00]
            }
    
    
    }
    
    

    and the assembly viewed in the simulation is as follows,

        42:         __asm
        43:         {
    0x00005000 B510      PUSH     {r4,lr}
        44:                   LDR       r0,[pc,#74]
    0x00005002 F8DF004A  LDR.W    r0,[pc,#74]  ; @0x00005050
        45:                   LDRSB  r0,[r0,#0x00]
    0x00005006 F9900000  LDRSB    r0,[r0,#0x00]
        46:                   LDR       r1,[pc,#74]
    0x0000500A F8DF104A  LDR.W    r1,[pc,#74]  ; @0x00005058
        47:                         STR    r0,[r1,#0x00]
        48:         }
        49:
        50:
    0x0000500E 6008      STR      r0,[r1,#0x00]
    

Children