Demonstration of a spin lock

Dependencies:   ELEC350-Practicals-FZ429

Fork of Task617Solution-mbedos-FZ429 by University of Plymouth - Stages 1, 2 and 3

myasm.s

Committer:
noutram
Date:
2017-11-09
Revision:
8:ad00c9036add

File content as of revision 8:ad00c9036add:

    AREA asm_func, CODE, READONLY
; Export my_asm function location so that C compiler can find it and link
    EXPORT myasm
myasm
    
    ; Write assmebler here
    MOV R1, #0x20000000
    BX      R1              ; THIS IS BAD
    BX      LR
    
    EXPORT spinlock
spinlock
    LDREX   R1,[R0]     ;Read counter
    SUBS    R1, #1      ;Subtract 1
    ITT     PL          ;IF True True >= 0
    STREXPL R2,R1,[R0]      ;TRY UPDATE
    CMPPL   R2,#0           ;SUCCEED?
    BNE     spinlock
    BX      LR

    EXPORT spinunlock
spinunlock
    LDREX   R1,[R0]
    ADD     R1,#1
    STREX   R2,R1,[R0]
    CMP     R2,#0
    BNE     spinunlock
    BX      LR
    END