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.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

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