30 lines
496 B
ArmAsm
30 lines
496 B
ArmAsm
|
.var mutex
|
||
|
.var count
|
||
|
|
||
|
.main
|
||
|
.top
|
||
|
|
||
|
.acquire
|
||
|
mov mutex, %ax
|
||
|
test $0, %ax
|
||
|
jne .acquire
|
||
|
mov $1, %ax
|
||
|
xchg %ax, mutex # atomic swap of 1 and mutex
|
||
|
test $0, %ax # if we get 0 back: lock is free!
|
||
|
jne .acquire # if not, try again
|
||
|
|
||
|
# critical section
|
||
|
mov count, %ax # get the value at the address
|
||
|
add $1, %ax # increment it
|
||
|
mov %ax, count # store it back
|
||
|
|
||
|
# release lock
|
||
|
mov $0, mutex
|
||
|
|
||
|
# see if we're still looping
|
||
|
sub $1, %bx
|
||
|
test $0, %bx
|
||
|
jgt .top
|
||
|
|
||
|
halt
|