9 years, 10 months ago.

How to use Assembly Code? to use Register r5

I'm trying Assembly code in mbed.

Board is Nucleo F401RE.

It seems break program when use Register r5,r6....

Only r0,r1,r2,r3,r4 well.

I see

http://mbed.org/cookbook/Assembly-Language

But not find it.

Which document can I read to understand this.

My assembly Code

__asm   void dcf(S32 *param ,S16 *signal){
    LDR    r3,[r0 , #0]
    LDR    r4,[r1 , #0]
    SMULWB   r2,r3,r4
    LDR    r5,[r0 , #4]; This Break Program
    LDR    r6,[r1 , #4]
    SMLAWB  r2,r5,r6,r2
    LDR    r3,[r0 , #8]
    LDR    r4,[r1 , #8]
    SMLAWB   r2,r3,r4,r2
    LDR    r5,[r0 , #12]
    LDR    r6,[r1 , #12]
    SMLAWB  r2,r5,r6,r2
    LDR    r3,[r0 , #16]
    LDR    r4,[r1 , #16]
    SMLAWB  r2,r3,r4,r2
    
    MOV     r0,r1; MOVS?
    LDR     r4,[r1, #12]; dcf_y1
    LDR     r3,[r0, #4]; dcf_x1
    STR     r4,[r1, #16]; dcf_y2 = dcf_y1
    STR     r3,[r0, #8]; dcf_x2 = dcf_x1
    STR     r5,[r1, #0]; sample
    STR     r2,[r0, #12]; dcf_y1 = result
    STR     r5,[r1 ,#4]; dcf_x1 = sample

    BX      LR
    ENDP
            
    ALIGN
    END
}


1 Answer

9 years, 10 months ago.

Hi,

According to the AAPCS (ARM Archtecture Procedure Call Standard), a subroutine must preserve (into stack) the contents of the registers r4-r8, r10, r11 and SP before they are used. Please see more detail in section 5.1.1 Core registers of AAPCS.

Regards, Toyo

Accepted Answer

I added PUSH POP {r4-r7}. It works well now.

Thanks.

posted by p igmon 09 Jun 2014