Given C code:
lock(lk);
shvar=max(shvar.x);
unlock(lk);
It is given that: use ll/sc to perform an atomic update of the shvar variable directly, without using lock() and unlock().
MIPS code for the given C:
try: ll $t0, 0($a1) #load linked will load the value from memory and monitor the memory location to check if any process performs write to it
slt $t1, $t0, $a2 #set to less than will check the values of $t0 and $a2, if $t0 is less then $a2, then $t1 will be set to 1
bnez $t1, skip # check for the value of $t1, if the value is not equal to zero , then will branch to skip function
mov $t0, $a2 # value of $a2 will be moved to $t0
sc $t0, 0($a1) #store conditionals will store the value to the memory, if there is no writes to the monitored memory address.
beqz $t0,try #Checks the value of $t0 , if the value is zero , then the branch will move to try function.
skip: