Note #2

Parallelism

The following sequence implements an atomic exchange on the memory location specified by the contents of $s1:

again: addi $t0, $zero, 1      #copy locked value
       ll $t1, 0($s1)          #load linked
       sc $t0, 0($s1)          #store conditional
       beq $t0, $zero, again   #branch if store fails
       add $s4, $zero, $t1     #put load value in $s4

Any time a processor intervenes and modifies the value in memory between the ll and sc instructions, the sc returns 0 in $t0, causing the code sequence to try again. At the end of this sequence the contents of $s4 and the memory location specified by $s1 have been atomically exchanged.

Pseudoinstructions

As

move $t0, $t1

is actually

add $t0, $zero, $t1

.
Others like: blt, bgt, bge, ble and etc. The cost is reserving one register, $at, for use by the assembler.

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,049評論 0 23
  • 在冬天最冷的日子里,給自己最深的擁抱! 我一直都以為我擁有全世界,到最后的最后,發(fā)現(xiàn),我擁有的最多 也最可靠的只有...
    lnaikey閱讀 109評論 0 2
  • 每天的晨讀內(nèi)容都是能量滿滿,雖然我寫不出來多么優(yōu)美的文字出來,但是堅持每天的分享對自己幫助很大,現(xiàn)在編輯文字比以前...
    石話石說簡書閱讀 182評論 0 1
  • 昨天去公園散步,在湖邊玩耍的一個小男孩,抬頭看了看我,給了我一個微笑,那個微笑,燦爛,明媚。我的心頓時被融化了,我...
    bluecafe閱讀 533評論 4 3

友情鏈接更多精彩內(nèi)容