《操作系统》的实验代码。
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

27 行
480 B

  1. .var flag
  2. .var count
  3. .main
  4. .top
  5. .acquire
  6. mov flag, %ax # get flag
  7. test $0, %ax # if we get 0 back: lock is free!
  8. jne .acquire # if not, try again
  9. mov $1, flag # store 1 into flag
  10. # critical section
  11. mov count, %ax # get the value at the address
  12. add $1, %ax # increment it
  13. mov %ax, count # store it back
  14. # release lock
  15. mov $0, flag # clear the flag now
  16. # see if we're still looping
  17. sub $1, %bx
  18. test $0, %bx
  19. jgt .top
  20. halt