:add lab7 spoc exercise related codes

This commit is contained in:
yuchen
2015-04-29 12:38:37 +08:00
parent 69afb3405b
commit f9b1bb3b66
14 changed files with 2643 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
.var mutex
.var count
.main
.top
.acquire
mov $1, %ax
xchg %ax, mutex # atomic swap of 1 and mutex
test $0, %ax # if we get 0 back: lock is free!
je .acquire_done
yield # if not, yield and try again
j .acquire
.acquire_done
# 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