Repeat Exercise 2.43, but this time use ll/sc to perform an atomic update of the shvar variable

Question:

Repeat Exercise 2.43, but this time use ll/sc to perform an atomic update of the shvar variable directly, without using lock() and unlock(). Note that in this problem there is no variable lk.


Exercise 2.43

Write the MIPS assembly code to implement the following C code:
lock(lk);
shvar=max(shvar,x);
unlock(lk);
Assume that the address of the lk variable is in $a0, the address of the shvar variable is in $a1, and the value of variable x is in $a2. Your critical section should not contain any function calls. Use ll/sc instructions to implement the lock( ) operation, and the unlock() operation is simply an ordinary store instruction.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Computer Organization and Design The Hardware Software Interface

ISBN: 978-0124077263

5th edition

Authors: David A. Patterson, John L. Hennessy

Question Posted: