《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
476 B

  1. .var ticket
  2. .var turn
  3. .var count
  4. .main
  5. .top
  6. .acquire
  7. mov $1, %ax
  8. fetchadd %ax, ticket # grab a ticket (keep it in dx)
  9. .tryagain
  10. mov turn, %cx # check if it's your turn
  11. test %cx, %ax
  12. jne .tryagain
  13. # critical section
  14. mov count, %ax # get the value at the address
  15. add $1, %ax # increment it
  16. mov %ax, count # store it back
  17. # release lock
  18. mov $1, %ax
  19. fetchadd %ax, turn
  20. # see if we're still looping
  21. sub $1, %bx
  22. test $0, %bx
  23. jgt .top
  24. halt