SlideServe
Menu
Préférences
© SlideServe · v2026

Intro to Computer Org.

helena avatar
32 diapositives · 561 Views · Oct 09, 2014

Intro to Computer Org. MIPS Architecture & Assembly: More Instructions. MIPS Assembly Instructions. All MIPS instructions are one of these three types. R-type All the data is in registers I-type Only way to load from/store to memory Uses registers + hardcoded data J-type

Intro to Computer Org. - slide 1
01 / 32Intro to Computer Org.
1 / 17

Télécharger la présentation

Intro to Computer Org.
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Intro to Computer Org. MIPS Architecture & Assembly: More Instructions

  2. MIPS Assembly Instructions • All MIPS instructions are one of these three types. • R-type • All the data is in registers • I-type • Only way to load from/store to memory • Uses registers + hardcoded data • J-type • Uses only hardcoded data

  3. MIPS Assembly – R-types • R-type instructions include: • add – Addition • sub – Subtraction • and, or, xor, nor – Logical and, or, exclusive or, nor • sll, srl – Shift Left/Right Logical • slt – Set Less Than • jr – Jump Register

  4. MIPS Assembly – R-types • slt – Set if less than • If source 1 < source 2, dest = 1 • Else, dest = 0 • Very useful in combination with beq & bne.

  5. MIPS Assembly – R-types • jr – Jump Register • Jumps to the address contained within the specified register. • Usual format: jr $ra

  6. MIPS Assembly – I-types • I-type instructions include: • addi – Addition • andi, ori, xori – Logical and, or, exclusive or • slti – Set Less Than • beq, bne – Branch If Equal/Not Equal • lw, sw – Load Word/Store Word

  7. MIPS Assembly – J-types • J-type instructions include: • j – Jump • jal – Jump and Link

  8. MIPS Assembly – J-types • jal – Jump and Link • Performs a regular jump to the specified label • Saves the address of the instruction after the jal in $ra

  9. MIPS Assembly - Shortcuts • In addition to regular instructions, there are also pseudoinstructions that represent very common operations. • We’ll worry about using the real instructions for these basic operations later.

  10. MIPS Assembly - Shortcuts • move $t1, $t0 • Copies contents of the source register ($t0) to the destination register ($t1) • li $t1, <integer> • Loads a constant value directly into a register. • la $t1, label • Loads an address into a register

  11. Basic MIPS Programming • To write a comment in MIPS, precede it with the sharp sign. (#) #This is a comment. • To make a label for branches and jumps… label: <instruction>

  12. Basic MIPS Programming • Now that we have some of the basic MIPS instructions, how can we use them to write meaningful programs?

  13. If – Then – Else • Let’s consider the following code: if($t0 == $t1) $t2 = 4; else $t2 = 5; • How can we make this in MIPS?

  14. If – Then – Else • Let’s work this out on the blackboard.

  15. if($t0 == $t1) $t2 = 4; else $t2 = 5; if: bne $t0, $t1, else li $t2, 4 j end else: li $t2, 5 end: #Whatever’s next. If – Then – Else

  16. If – Then – Else • With an if, we wish to execute the next line of code if the condition is true. • But with a beq or a bne, we execute the next line of code if the condition is false. • Thus, we test the opposite of what the original if tested.

  17. For - Next • Let’s consider the following code: int sum = 0; for(int i = 1; i <= 10; i++) { sum += i; }

  18. For - Next for(int i = 1; i <= 10; i++) • int i = 1 //Initialization • i <= 10 //Test • i++ //Increment

  19. int sum = 0; for(int i = 1; i <= 10; i++) { sum += i; } li $t1, 0 init: li $t0, 0 li $t3, 10 test: slti $t2, $t3, $t0 bne $t2, $0, end body: add $t1, $t1, $t0 incr: addi $t0, $t0, 1 j test end: #Whatever’s next. For – Next

  20. For – Next • While in that example we could have moved the test to the end, it is not always possible to do so. for(int i=0; i < a.length; i++) { //Body of loop }

  21. Using References/Pointers array[5] += 4

  22. Using References/Pointers la $t0, array lw $t1, 20($t0) # 20 = 5 * 4 addi $t1, $t1, 4 sw $t1, 20($t0)

  23. Using References/Pointers //Assume that value has offset 0 //and next has offset 4. struct Node { int value; Node* next; }

  24. //C++ version struct Node { int value; Node* next; } //Java version class Node { public int value; public Node next; } Using References/Pointers

  25. Using References/Pointers //Assume that value has byte offset 0 //and next has byte offset 4. struct Node { int value; Node* next; }

  26. Using References/Pointers struct Node { int value; Node* next; } ... //Assume a preexisting Node ‘root’. Node* curNode = root; curNode = curNode->next; curNode->value = 5;

  27. Using References/Pointers la $t0, root #t0 = curNode lw $t0, 4($t0) li $t1, 5 sw $t1, 0($t0)

  28. Other Useful Instructions • mult $t0, $t1 • Performs integer multiplication • Places the result in special registers called Hi and Lo. • Multiplying two 32-bit integers can potentially give a 64-bit result.

  29. Other Useful Instructions • div $t0, $t1 • Performs integer division • Places the result Lo and the remainder in Hi. • Integer division cannot give fractional numbers.

  30. Other Useful Instructions • mfhi $t0 • Moves contents of Hi into $t0 • mflo $t0 • Moves contents of Lo into $t0

  31. Other Useful Instructions • sllv, srlv $t0, $t1, $t2 • Shift left/right logical variable • Replaces the hardcoded shift value with one in a register • Uses value of that register modulus 32.

  32. Other Useful Instructions • Before continuing with other instructions, we need to examine the nature of the data we’re working with. • Coming next: Integer and floating-point representations!