I am using a MSP 432 and have to create an assembly functions in C. I tried creating the functions using __asm void PendSV_Handler{}
. But that does not work and says Expected an Identifier.
Also, I am trying to run this assembler command cpsid i
but it says CPSID
is undefined but CPSIE i
works. I am a bit confused at this point. I am fairly new to this and I am still learning.
Below is the code I am trying to make assembly. I try making the function assembly by doing __asm void PendSV_handler
.
I was not sure if it would be easier to just create a asm. file with these instructions.
OSThread *volatile OS_curr;
OSThread *volatile OS_next;
void PendSV_Handler(void){
__asm__("cpsid i"
//if(OS_curr != (OSThread *)0)
"ldr r0, =OS_curr"
"ldr r0, [r0]"
"cbz r0, PendSV_restore");
// Push r4 - r11
__asm__("PUSH {r4-r11}"
"ldr r1, =OS_curr"
"ldr r1, [r1]"
// OS_curr -> sp = sp;
"str sp, [r1]");
PendSV_restore
// sp=OS_next -> sp;
__asm__("ldr r0, =OS_next;"
"ldr r0, [r0]"
"ldr r0, [r0]"
"str sp, [r13]");
// OS_curr = OS_next;
__asm__("ldr r0, =OS_next"
"ldr r1, [pc, 0xc]"
"ldr r0, =OS_curr"
"str r0, [r1]"
//Pop r4-r11
"POP {r4-r11}"
// __enable_interrupts();
"cpsie i"
//return to next thread
"bx r14");
}