9. Q6

$ python ./x86.py -p test-and-set.s -R ax,bx -a bx=2 -M mutex,count -c -i 6

mutex count      ax    bx          Thread 0                Thread 1

    0     0       0     2
    0     0       1     2   1000 mov  $1, %ax
    1     0       0     2   1001 xchg %ax, mutex
    1     0       0     2   1002 test $0, %ax
    1     0       0     2   1003 jne  .acquire
    1     0       0     2   1004 mov  count, %ax
    1     0       1     2   1005 add  $1, %ax
    1     0       0     2   ------ Interrupt ------  ------ Interrupt ------
    1     0       1     2                            1000 mov  $1, %ax
    1     0       1     2                            1001 xchg %ax, mutex
    1     0       1     2                            1002 test $0, %ax
    1     0       1     2                            1003 jne  .acquire
    1     0       1     2                            1000 mov  $1, %ax
    1     0       1     2                            1001 xchg %ax, mutex
    1     0       1     2   ------ Interrupt ------  ------ Interrupt ------
    1     1       1     2   1006 mov  %ax, count
    0     1       1     2   1007 mov  $0, mutex
    0     1       1     1   1008 sub  $1, %bx
    0     1       1     1   1009 test $0, %bx
    0     1       1     1   1010 jgt .top
    0     1       1     1   1000 mov  $1, %ax
    0     1       1     2   ------ Interrupt ------  ------ Interrupt ------
    0     1       1     2                            1002 test $0, %ax
    0     1       1     2                            1003 jne  .acquire
    0     1       1     2                            1000 mov  $1, %ax
    1     1       0     2                            1001 xchg %ax, mutex
    1     1       0     2                            1002 test $0, %ax
    1     1       0     2                            1003 jne  .acquire
    1     1       1     1   ------ Interrupt ------  ------ Interrupt ------
    1     1       1     1   1001 xchg %ax, mutex
    1     1       1     1   1002 test $0, %ax
    1     1       1     1   1003 jne  .acquire
    1     1       1     1   1000 mov  $1, %ax
    1     1       1     1   1001 xchg %ax, mutex
    1     1       1     1   1002 test $0, %ax
    1     1       0     2   ------ Interrupt ------  ------ Interrupt ------
     
mutex count      ax    bx          Thread 0                Thread 1

    1     1       1     2                            1004 mov  count, %ax
    1     1       2     2                            1005 add  $1, %ax
    1     2       2     2                            1006 mov  %ax, count
    0     2       2     2                            1007 mov  $0, mutex
    0     2       2     1                            1008 sub  $1, %bx
    0     2       2     1                            1009 test $0, %bx
    0     2       1     1   ------ Interrupt ------  ------ Interrupt ------
    0     2       1     1   1003 jne  .acquire
    0     2       1     1   1000 mov  $1, %ax
    1     2       0     1   1001 xchg %ax, mutex
    1     2       0     1   1002 test $0, %ax
    1     2       0     1   1003 jne  .acquire
    1     2       2     1   1004 mov  count, %ax
    1     2       2     1   ------ Interrupt ------  ------ Interrupt ------
    1     2       2     1                            1010 jgt .top
    1     2       1     1                            1000 mov  $1, %ax
    1     2       1     1                            1001 xchg %ax, mutex
    1     2       1     1                            1002 test $0, %ax
    1     2       1     1                            1003 jne  .acquire
    1     2       1     1                            1000 mov  $1, %ax
    1     2       2     1   ------ Interrupt ------  ------ Interrupt ------
    1     2       3     1   1005 add  $1, %ax
    1     3       3     1   1006 mov  %ax, count
    0     3       3     1   1007 mov  $0, mutex
    0     3       3     0   1008 sub  $1, %bx
    0     3       3     0   1009 test $0, %bx
    0     3       3     0   1010 jgt .top
    0     3       1     1   ------ Interrupt ------  ------ Interrupt ------
    1     3       0     1                            1001 xchg %ax, mutex
    1     3       0     1                            1002 test $0, %ax
    1     3       0     1                            1003 jne  .acquire
    1     3       3     1                            1004 mov  count, %ax
    1     3       4     1                            1005 add  $1, %ax
    1     4       4     1                            1006 mov  %ax, count
    1     4       3     0   ------ Interrupt ------  ------ Interrupt ------
    1     4       3     0   1011 halt
    1     4       4     1   ----- Halt;Switch -----  ----- Halt;Switch -----
    0     4       4     1                            1007 mov  $0, mutex
    0     4       4     0                            1008 sub  $1, %bx
    0     4       4     0                            1009 test $0, %bx
    0     4       4     0                            1010 jgt .top
    0     4       4     0                            1011 halt