The following code block is to swap values stored at two memory addresses $s1 and $s3: lw
Question:
The following code block is to swap values stored at two memory addresses $s1 and $s3:
lw $s0, 0($s1)
lw $s2, 0($s3)
sw $s0, 0($s3)
sw $s2, 0($s1)
However, in a multiprocessing environment, this wouldn't work since between the first line and the last line, if some other thread changes the content of the memory at addresses $s1 and/or $s3, it will create a mess (the swap would not be implemented correctly). In such an environment, you need LL and SC to ensure that the swap is atomic: when the last line is run, the content at addresses $s1 and $s3 has not been changed since after the first line. Modify the above code (which is properly commented) to implement the atomic swap.
Computer Organization and Design The Hardware Software Interface
ISBN: 978-0124077263
5th edition
Authors: David A. Patterson, John L. Hennessy