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...
    又是夜半惊坐起阅读 13,474评论 0 23
  • 在冬天最冷的日子里,给自己最深的拥抱! 我一直都以为我拥有全世界,到最后的最后,发现,我拥有的最多 也最可靠的只有...
    lnaikey阅读 669评论 0 2
  • 每天的晨读内容都是能量满满,虽然我写不出来多么优美的文字出来,但是坚持每天的分享对自己帮助很大,现在编辑文字比以前...
    石话石说简书阅读 1,059评论 0 1
  • 昨天去公园散步,在湖边玩耍的一个小男孩,抬头看了看我,给了我一个微笑,那个微笑,灿烂,明媚。我的心顿时被融化了,我...
    bluecafe阅读 3,359评论 4 3