Note #1

作者: coCk_roBin | 来源:发表于2017-02-05 16:54 被阅读0次

Basic operations

source code in C:

array[300] = a + array[300];

compiled to MIPS, suppose array in $t1 and a in $s2:

lw $t0, 1200($t1)
add $t0, $s2, $t0
sw $t0, 1200($t1)

then to machine code (Base 10):

op rs rt rd shamt funct address
35 9 8 / / / 1200
0 18 8 8 0 32 /
43 9 8 / / / 1200

notes that 3510 = 1000112, 4310 = 1010112.

Conditional Branches

source code in C:

if (i == j)
  f = g + h;
else
  f = g - h;

compiled to MIPS, suppose f to j in $s0 to $s4:

bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit
Else: sub $s0, $s1, $s2
Exit:

Loops

source code in C:

while (array[i] == k)
  i += 1;

compiled to MIPS, suppose i in $s3, k in $s5 and array in $s6:

Loop: sll $t1, $s3 , 2   # Temp reg $t1 = i * 4
add $t1, $t1, $s6   # Thus we want $t1($s6)
lw $t0, 0($t1)
bne $t0, $s5, Exit
addi $s3, $s3, 1
j Loop
Exit:

Reference

P&H Computer Architecture and Design

相关文章

  • 双主模型keepalived高可用集群

    ipvs(keepalived) 1、note1、note2,设置单主模式keepalived 2、note1、n...

  • Note 1

    突然想写写日记,反正在这里谁都不知道我是谁。 我的性格就是这样。希望别人不知道我,然而又堂而皇之地干这干那。 昨天...

  • Note #1

    Basic operations source code in C: compiled to MIPS, supp...

  • Apache Hive Essentials笔记

    Apache Hive Essentials笔记 1.CASCADE Note: Note that Hive k...

  • EN Note # A Study in Scarlet, Ch

    上接 EN Note # A Study in Scarlet, Chapter 1-7以及EN Note # A...

  • spring

    spring.note[note://E4366FAD81674393B430151D2D1FD42F] //1....

  • Week 1 Note

    Words and Expressions (Chapter1-9) Chapter 1&2 (The Trans...

  • ENGLISH NOTE(1)

    I'm still working on it. means : I still need more time.g...

  • note1

    git mkdir name cd name git clone https://github.com/Berke...

  • NOTE_1

    人应该对过去的选择抱有敬畏之心。 后悔看似指向过去的自己,本质上是攻击当下的自己。 不喜欢自己,不接纳自己,你的灵...

网友评论

      本文标题:Note #1

      本文链接:https://www.haomeiwen.com/subject/mwseittx.html