How to Cgange C code to assembly code locklk shvarmaxshvarx

How to Cgange C code to assembly code?


lock(lk): shvar=max(shvar.x); unlock(lk): Assume that the address of the 1k variable is in $a0, the address of the shvar variable is in $al, and the value of variable x is in $a 2. Your critical section should not contain any function calls. Use 11sc instructions to implement the lock) operation, and the unlock() operation is simply an ordinary store instruction.

Solution

Answer

ll $a0 #locking

cmp $a1, $a2 #compare shvar and x

jg store # go to store if shvar > x

mov $a1, $a2 # if x>shvar, store x in shvar

store:

mov $a1, $a1 # keeping shvar as it is

sc $a0 #unlocking

How to Cgange C code to assembly code? lock(lk): shvar=max(shvar.x); unlock(lk): Assume that the address of the 1k variable is in $a0, the address of the shvar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site