MIPS Procedures - Florida State University

MIPS Procedures - Florida State University

MIPS Coding Review Everything is stored in the computer as sequences of 0s and 1s Each assembly instruction is uniquely mapped to a unique sequence of 0s and 1s There are three types of instruction types in MIPS: R-Types: opcode, rs, rt, rd, shamt, funt I-Types: opcode, rs, rt, immediate J-Types: opcode, immediate Review opcode (6 bits): defines the operation rs/rt/rd (5 bits): register names / address shamt (5 bits): amount to shift in sll/srl funct (6 bits): further defines R-Types immediate (16 bits for I-Type / 26 for J-Type): addresses and constants Exercise the bubble sort for (int i = 0; i < N-1; i++) {

for (int j = 0; j < N-i-1; j++) { if (A[j] < A[j+1]) swap(A[j], A[j+1]); } } 01/25/20 week04-3.ppt 4 Exercise the bubble sort Need two loops just encapsulate one in the other Need to read the elements done before. Need to compare two numbers done before Need to swap not that hard .data .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 A: .text .globl main main: la $s7, A li $s6, 9

done: li $v0,10 syscall Setup the program # Address of A # N-1 .data .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 A: .text .globl main main: la $s7, A li $s6, 9 # getting the address # N-1 li $s0, 0 # i = 0 addi $s0, $s0, 1

bne $s0, $s6, LOOP1 # i = i + 1 # if i != N-1, outer loop again LOOP1: done: li $v0,10 syscall Getting the first loop done A: .data .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: LOOP1: LOOP2: done: la $s7, A

li $s6, 9 # getting the address # N-1 li $s0, 0 li $s1, 0 # i = 0 # j = 0 addi $s1, $s1, 1 sub $t7, $s6, $s0 bne $s1, $t7, LOOP2 addi $s0, $s0, 1 bne $s0, $s6, LOOP1 # # # # # li $v0,10 syscall Getting both loop done j = j + 1

$t7 will get N-1-i if j != N-1-i, inner loop again i = i + 1 if i != N-1, outer loop again A: .data .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: LOOP1: LOOP2: done: la $s7, A li $s6, 9 # getting the address # N-1 li $s0, 0 li $s1, 0 sll $t0, $s1, 2 add $t0, $t0, $s7

lw $t1, 0($t0) lw $t2, 4($t0) # # # # # # i = j = $t0 $t0 $t1 $t2 addi $s1, $s1, 1 sub $t7, $s6, $s0 bne $s1, $t7, LOOP2 addi $s0, $s0, 1 bne $s0, $s6, LOOP1 # # # # #

j = j + 1 $t7 will get N-1-i if j != N-1-i, inner loop again i = i + 1 if i != N-1, outer loop again 0 0 = j * 4 is the address of = A[j] = A[j+1] A[j] li $v0,10 syscall Adding the code to read the elements A[j] and A[j+1] A: .data .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main:

LOOP1: LOOP2: L1: done: la $s7, A li $s6, 9 # getting the address # N-1 li $s0, 0 li $s1, 0 sll $t0, $s1, 2 add $t0, $t0, $s7 lw $t1, 0($t0) lw $t2, 4($t0) bgt $t1, $t2, L1 sw $t1, 4($t0) sw $t2, 0($t0) addi $s1, $s1, 1 sub $t7, $s6, $s0 bne $s1, $t7, LOOP2 addi $s0, $s0, 1 bne $s0, $s6, LOOP1

# # # # # # # # # # # # # # i = 0 j = 0 $t0 = j * 4 $t0 is the address of A[j] $t1 = A[j] $t2 = A[j+1] if A[j] > A[j+1] goto L1, bypass the swapping do the swap do the swap j = j + 1 $t7 will get N-1-i if j != N-1-i, inner loop again i = i + 1

if i != N-1, outer loop again li $v0,10 syscall Adding the comparison and swapping Pseudo instruction A pseudo instruction is not a real instruction supported by the hardware. It is created to make the coding easier. It is mapped to a unique sequence of real instructions by the assembler. blt $t0, $t1, L1 slt $at, $t0, $t1 bne $at, $0, L1 bgt $t0, $t1, L1 slt $at, $t1, $t0 bne $at, $0, L1 ble $t0, $t1, L1 lui $t0, 0x0003 ori $t0, $0, 0xBF20

slt $at, $t0, $t1 beq $at, $0, L1 not $t0, $s0 nor $t0, $s0, $0 slt $at, $t1, $t0 beq $at, $0, L1 bge $t0, $t1, L1 li/la $t0, 0x3BF20 move $t0, $t1 ori $t0, $t1, $0 http://www.utdallas.edu/~cantre ll/ee2310/spim.inst.txt In-class exercise -- Loop

Recently Viewed Presentations

  • Lesson 7.2: Tree of Life - Ms. Woodard&#x27;s Marine Science Class

    Lesson 7.2: Tree of Life - Ms. Woodard's Marine Science Class

    I can identify the 6 Kingdoms on the tree of life. I can describe characteristics of each of the 6 Kingdoms. I can classify an organism into its appropriate Kingdom. Domain. ... Phylum Anthophyta = Flowering Plants (Seagrass & Mangroves)...
  • Telfer School of Managements Research Support Centre presentation

    Telfer School of Managements Research Support Centre presentation

    Kaija I. Metuzals Affiliation: Adjunct Professor, Telfer School of Management Experience: Fisheries Stock Assessment and Management in Canada and EU Current interests: Causes and extent of IUU (Illegal, Unreported and Unregulated) fishing Bycatch Dr. Howard Powles Affiliation Adjunct Professor, Telfer...
  • Sales and Distribution SD - Sacramento State

    Sales and Distribution SD - Sacramento State

    Your employees use the Cross-Application Time Sheet (CATS) to record information on their working times. You can use the recorded data for further business processes in Human Resources, Logistics, and Controlling.
  • The Biological Bases of Behaviour - ednet.ns.ca

    The Biological Bases of Behaviour - ednet.ns.ca

    It is involved in learning, remembering, thinking and consciousness. It is divided into two halves or hemispheres that are connected by the corpus callosum. The cerebrum is in charge of taking in all of the information from the rest of...
  • Impact of Trauma on Children Kimberly McGrath, Psy.D.

    Impact of Trauma on Children Kimberly McGrath, Psy.D.

    www.uq.edu.au. Emotional Response. Difficulty identifying, expressing, and managing emotions. May lack or have limited language for feeling states. ... Learn they cannot trust, the world is not safe, and that they are powerless.
  • Lcls R &amp; D

    Lcls R & D

    For security, server resides behind SLAC firewall and only viewable within the SLAC domain remote users can only view it if they have a SLAC account operating, for example, with VPN anyone at SLAC can in principal write to the...
  • Distribution Game - California State University, Sacramento

    Distribution Game - California State University, Sacramento

    More info at erpsim.hec.ca. Elements of a winning strategy. Use the ERP system efficiently. Do not run out of stock. Delays, production capacities and liquidity constraints are important elements of the game. ... Distribution Game Last modified by:
  • Light production Thanks to Rebekah Wilkins, Jackie ORiley

    Light production Thanks to Rebekah Wilkins, Jackie ORiley

    Rebekah Wilkins, Jackie O'Riley * * * * * * * * Perciformes Lophiiformes Perciformes Light production in fishes Who? scattered among 13 orders, 45 families (Bond Table 19-1) mostly in teleosts, 2 families of elasmobranches Where?