7. Q4

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

 flag count      ax    bx          Thread 0                Thread 1

    0     0       0     2
    0     0       0     2   1000 mov  flag, %ax
    0     0       0     2   1001 test $0, %ax
    0     0       0     2   1002 jne  .acquire
    1     0       0     2   1003 mov  $1, flag
    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  flag, %ax
    1     0       1     2                            1001 test $0, %ax
    1     0       1     2                            1002 jne  .acquire
    1     0       1     2                            1000 mov  flag, %ax
    1     0       1     2                            1001 test $0, %ax
    1     0       1     2                            1002 jne  .acquire
    1     0       1     2   ------ Interrupt ------  ------ Interrupt ------
    1     1       1     2   1006 mov  %ax, count
    0     1       1     2   1007 mov  $0, flag
    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       0     1   1000 mov  flag, %ax
    0     1       1     2   ------ Interrupt ------  ------ Interrupt ------
    0     1       0     2                            1000 mov  flag, %ax
    0     1       0     2                            1001 test $0, %ax
    0     1       0     2                            1002 jne  .acquire
    1     1       0     2                            1003 mov  $1, flag
    1     1       1     2                            1004 mov  count, %ax
    1     1       2     2                            1005 add  $1, %ax
    1     1       0     1   ------ Interrupt ------  ------ Interrupt ------
     
 flag count      ax    bx          Thread 0                Thread 1

    1     1       0     1   1001 test $0, %ax
    1     1       0     1   1002 jne  .acquire
    1     1       0     1   1003 mov  $1, flag
    1     1       1     1   1004 mov  count, %ax
    1     1       2     1   1005 add  $1, %ax
    1     2       2     1   1006 mov  %ax, count
    1     2       2     2   ------ Interrupt ------  ------ Interrupt ------
    1     2       2     2                            1006 mov  %ax, count
    0     2       2     2                            1007 mov  $0, flag
    0     2       2     1                            1008 sub  $1, %bx
    0     2       2     1                            1009 test $0, %bx
    0     2       2     1                            1010 jgt .top
    0     2       0     1                            1000 mov  flag, %ax
    0     2       2     1   ------ Interrupt ------  ------ Interrupt ------
    0     2       2     1   1007 mov  $0, flag
    0     2       2     0   1008 sub  $1, %bx
    0     2       2     0   1009 test $0, %bx
    0     2       2     0   1010 jgt .top
    0     2       2     0   1011 halt
    0     2       0     1   ----- Halt;Switch -----  ----- Halt;Switch -----
    0     2       0     1                            1001 test $0, %ax
    0     2       0     1   ------ Interrupt ------  ------ Interrupt ------
    0     2       0     1                            1002 jne  .acquire
    1     2       0     1                            1003 mov  $1, flag
    1     2       2     1                            1004 mov  count, %ax
    1     2       3     1                            1005 add  $1, %ax
    1     3       3     1                            1006 mov  %ax, count
    0     3       3     1                            1007 mov  $0, flag
    0     3       3     1   ------ Interrupt ------  ------ Interrupt ------
    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       3     0                            1011 halt