内联臂装配函数在模块或Keil中

时间:2022-05-15 03:13:47

How can I write inline ARM Assembly functions in Emblocks or in Keil for STM32F429 microcontroller?

如何为STM32F429单片机在Emblocks或Keil中编写内联ARM装配函数?

2 个解决方案

#1


0  

I already have given up to find a soluton for the inline assembly. I will be happy even if I found a soluton for the pure assembly .s/.asm I read a soluton on the Keil's page, it is not good, but I almost works weel. I have a problem with it, it does not recognise de constans like #2

我已经放弃寻找内联程序集的解决方案。即使我找到了一个纯粹集合的解决方案,我也会很高兴。asm我在Keil的页面上读了一个soluton,它不好,但是我几乎可以工作。我有个问题,它不像2号那样识别康德学派

Here is the example:

下面是例子:

AREA     ARMex, CODE, READONLY
                                ; Name this block of code ARMex
        ENTRY                   ; Mark first instruction to execute
start
        MOV      r0, #10        ; Set up parameters
        MOV      r1, #3
        ADD      r0, r0, r1     ; r0 = r0 + r1
stop
        MOV      r0, #0x18      ; angel_SWIreason_ReportException
        LDR      r1, =0x20026   ; ADP_Stopped_ApplicationExit
        SVC      #0x123456      ; ARM semihosting (formerly SWI)
        END                     ; Mark end of file

(It is not an answer, but I did not write it in the comment, because I wanted to format the code well.)

(这不是答案,但我没有在评论中写出来,因为我想把代码格式化得很好。)

#2


0  

This should work in Keil:

这在基尔应该行得通:

// #pragma ARM  // would do the same as __arm below !
void ChangeIRQ (unsigned int NewState) __arm  {  // use ARM-mode for this function
  __asm  {
     AND    R0,R0,#0         //
     MRS    R0,CPSR          //
     ORR    R0,R0,#0x80;     //

     LDAV   R1,R10,NewState  // load parameter-value 'NewState' into R1
     BIC    R0,R0,R1,LSL #7  //
     MSR    CPSR_c, R0       //
  }
}

I don't know EmBlocks, but IAR and GCC allow inline istructions like asm or __asm("mov x,y") (more parameters may specify registers,inputs,outputs).

我不知道emblock,但是IAR和GCC允许诸如asm或__asm(“mov x,y”)之类的内联istructions(更多的参数可以指定寄存器、输入和输出)。

This is my code for ATSAM4L (Cortex-M4) in IAR EWARM:

这是我在IAR EWARM中ATSAM4L (Cortex-M4)的代码:

__no_init uint reset_addr;
__no_init uint reset_reta;
__no_init uint reset_hfs;
__no_init uint reset_cfs;

extern "C" {

void HardFault(uint* stack);
__noreturn void HardFault_Handler() {
//  tst lr, #4
//  ite eq
//  mrseq r0,MSP
//  mrsne r0,PSP
    asm volatile ("MRS r0,MSP\nB HardFault"); }

void HardFault(uint* stack) {
    enum { r0, r1, r2, r3, r12, lr, pc, psr};
    reset_hfs = scb->hfs;   // fetch
    scb->hfs = reset_hfs;   // clear
    reset_cfs = scb->cfs;
    reset_addr = 0; reset_reta = 0;
    if(reset_hfs&SCB::FORCED) {
        reset_addr = stack[pc];
        reset_reta = stack[lr]; }
//  asm volatile ("BKPT 1");
    scb->softres();
}

#1


0  

I already have given up to find a soluton for the inline assembly. I will be happy even if I found a soluton for the pure assembly .s/.asm I read a soluton on the Keil's page, it is not good, but I almost works weel. I have a problem with it, it does not recognise de constans like #2

我已经放弃寻找内联程序集的解决方案。即使我找到了一个纯粹集合的解决方案,我也会很高兴。asm我在Keil的页面上读了一个soluton,它不好,但是我几乎可以工作。我有个问题,它不像2号那样识别康德学派

Here is the example:

下面是例子:

AREA     ARMex, CODE, READONLY
                                ; Name this block of code ARMex
        ENTRY                   ; Mark first instruction to execute
start
        MOV      r0, #10        ; Set up parameters
        MOV      r1, #3
        ADD      r0, r0, r1     ; r0 = r0 + r1
stop
        MOV      r0, #0x18      ; angel_SWIreason_ReportException
        LDR      r1, =0x20026   ; ADP_Stopped_ApplicationExit
        SVC      #0x123456      ; ARM semihosting (formerly SWI)
        END                     ; Mark end of file

(It is not an answer, but I did not write it in the comment, because I wanted to format the code well.)

(这不是答案,但我没有在评论中写出来,因为我想把代码格式化得很好。)

#2


0  

This should work in Keil:

这在基尔应该行得通:

// #pragma ARM  // would do the same as __arm below !
void ChangeIRQ (unsigned int NewState) __arm  {  // use ARM-mode for this function
  __asm  {
     AND    R0,R0,#0         //
     MRS    R0,CPSR          //
     ORR    R0,R0,#0x80;     //

     LDAV   R1,R10,NewState  // load parameter-value 'NewState' into R1
     BIC    R0,R0,R1,LSL #7  //
     MSR    CPSR_c, R0       //
  }
}

I don't know EmBlocks, but IAR and GCC allow inline istructions like asm or __asm("mov x,y") (more parameters may specify registers,inputs,outputs).

我不知道emblock,但是IAR和GCC允许诸如asm或__asm(“mov x,y”)之类的内联istructions(更多的参数可以指定寄存器、输入和输出)。

This is my code for ATSAM4L (Cortex-M4) in IAR EWARM:

这是我在IAR EWARM中ATSAM4L (Cortex-M4)的代码:

__no_init uint reset_addr;
__no_init uint reset_reta;
__no_init uint reset_hfs;
__no_init uint reset_cfs;

extern "C" {

void HardFault(uint* stack);
__noreturn void HardFault_Handler() {
//  tst lr, #4
//  ite eq
//  mrseq r0,MSP
//  mrsne r0,PSP
    asm volatile ("MRS r0,MSP\nB HardFault"); }

void HardFault(uint* stack) {
    enum { r0, r1, r2, r3, r12, lr, pc, psr};
    reset_hfs = scb->hfs;   // fetch
    scb->hfs = reset_hfs;   // clear
    reset_cfs = scb->cfs;
    reset_addr = 0; reset_reta = 0;
    if(reset_hfs&SCB::FORCED) {
        reset_addr = stack[pc];
        reset_reta = stack[lr]; }
//  asm volatile ("BKPT 1");
    scb->softres();
}