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

How can we check the register value in inline-assembly in c?

Dear all,

I'm trying to check the register values in inline-assembly in c as the below code.
In especially, R0 and R1 values what I want to know which value is loaded to register.
But as you can see that code, that is a In-line assembly.

Is there any way to check the register which values are loaded?

main.c

...
__asm void ST0(void)
{
   MOVS  R0,#0
   LDR   R1,[R0]     ; Get initial MSP value
   MOV   SP, R1
   LDR   R1,[R0, #4] ; Get initial PC value
   BX    R1
}
...

int main (void)
{


  ST0();
  return 0;
}

Parents
  • Hello Carter,

    You are using inline assembly here, so you are defining variables as R0, SP and so on. You are NOT using the actual registers on the device.

    To modify the real registers, you would have to use embedded assembly.

    See an example of embedded assembler:

    #include <stdio.h>
    __asm void my_strcpy(const char *src, char *dst)
    {
    loop
          LDRB  r2, [r0], #1
          STRB  r2, [r1], #1
          CMP   r2, #0
          BNE   loop
          BX    lr
    }
    int main(void)
    {
        const char *a = "Hello world!";
        char b[20];
        my_strcpy (a, b);
        printf("Original string: '%s'\n", a);
        printf("Copied   string: '%s'\n", b);
        return 0;
    }
    

    (from infocenter.arm.com/.../index.jsp )

    putting __asm in front of the function name lets you modify the registers directly.

Reply
  • Hello Carter,

    You are using inline assembly here, so you are defining variables as R0, SP and so on. You are NOT using the actual registers on the device.

    To modify the real registers, you would have to use embedded assembly.

    See an example of embedded assembler:

    #include <stdio.h>
    __asm void my_strcpy(const char *src, char *dst)
    {
    loop
          LDRB  r2, [r0], #1
          STRB  r2, [r1], #1
          CMP   r2, #0
          BNE   loop
          BX    lr
    }
    int main(void)
    {
        const char *a = "Hello world!";
        char b[20];
        my_strcpy (a, b);
        printf("Original string: '%s'\n", a);
        printf("Copied   string: '%s'\n", b);
        return 0;
    }
    

    (from infocenter.arm.com/.../index.jsp )

    putting __asm in front of the function name lets you modify the registers directly.

Children
No data