MIPS Coding. Exercise 1 4/17/2015week04-3.ppt2 Suppose we have three arrays, A, B, C, all of size 10. Now we want to set C[i] = min(A[i], B[i]) for all.

Slides:



Advertisements
Similar presentations
Exercises for CS1512 Week 12 Sets (questions).
Advertisements

Computer Science School of Computing Clemson University Introduction to Mathematical Reasoning Jason Hallstrom and Murali Sitaraman Clemson University.
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
MIPS Function Continued
1. What number does the following array represent?
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise Exercise Exercise
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
Lecture 2 Examples Pseudo code and flowcharts. Problem 1 Read a number as input and then print if it is even or odd.
LEARNING GUIDANCE PLAN 15mins for 8 day - class. Learning Guidance Plan No.Session 1Summary 2Personal Story 3Infer the scene 4Power reading PPT. Template.
Духовні символи Голосіївського району
WEEK 1 You have 10 seconds to name…
1 MIPS Assembly Language Programming CDA 3101 Discussion Section 04.
Learning Guidance Plan Storytelling: Magic tree house #1 8-time/1book 15-min class.
AP Computer Science. January 5, 2016 PowerPoint – Begin Array’s R7.1 R7.2 R7.6 E7.1 All this homework due Wednesday 1/6. Submit through Aspen pages Read.
爱迪科森 网上报告厅 WANGSHANGBAOGAOTING.  公司简介  发展历程  产品简介  2009 年新亮点  产品规模及内容  功能介绍及使用说明  产品特点  后台管理  制作系统  售后服务  公司资质  典型用户 目录.
DEVRY CIS 115 All Exercises Week 1 to Week 7 Check this A+ tutorial guideline at
BUS 642 Week 1 Exercises Complete the Following Exercises Complete Discussion Questions 1, 2, and 5 on page 22. Complete Making Research Decisions Question.
MGT 210 Week 3 Assignment Exercise 7-2 To purchase this material click on below link 210/MGT-210-Week-3-Assignment-Exercise-7-
PSY 210 Week 5 Exercise Conformity Response Appendix E To purchase this material click on below link 210/PSY-210-Week-5-Exercise-Conformity-
BSHS 332 Week 3 Learning Team Website Regulatory Exercise Check this A+ tutorial guideline at 332/BSHS-332-Week-3-Learning-Team-
MIPS Coding Continued.
MIPS instructions.
ACC 3020 Innovative Education--snaptutorial.com
ACC 5320 Innovative Education--snaptutorial.com
ACC 5325 Innovative Education--snaptutorial.com
MTH 209 Competitive Success/snaptutorial.com
HCS 341 Education on your terms/tutorialrank.com.
MTH 209 Education for Service/snaptutorial.com
MIPS coding.
MIPS Coding.
Computer Architecture and Assembly Language CS 233 Lecture 1
عنوان مقاله(B Titr 32) Article Title (Times New Roman 30)
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Lesson on Forces & Balanced v Unbalanced Forces
MIPS Coding Continued.
MIPS coding.
Computer Architecture and Assembly Language CS 233 Lecture 1
MIPS Processor.
First Team exercise Using innovation process from SOI (some early, some from part 3): Improve how to “retain” material from a class Improve how to demonstrate.
How to get started back at the job
MIPS Assembly.
Presentation transcript:

MIPS Coding

Exercise 1 4/17/2015week04-3.ppt2 Suppose we have three arrays, A, B, C, all of size 10. Now we want to set C[i] = min(A[i], B[i]) for all 0<= i <= 9.

Exercise 1 4/17/2015week04-3.ppt3 Suppose we have three arrays, A, B, C, all of size 10. Now we want to set C[i] = min(A[i], B[i]) for all 0<= i <= 9. First, we need a loop to walk through the elements (done before) Second, we need to be able to read the elements (done before) Third, we need to be able to compare two numbers (done before) Fourth, we need to write back to the memory (easy)

. data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 B:.word 90, 2, 93, 66, 8, 120, 121,11, 33, 9 C:.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.text.globl main main: la $s0, A la $s1, B la $s2, C li $s3, 10 done:li $v0,10 syscall

. data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 B:.word 90, 2, 93, 66, 8, 120, 121,11, 33, 9 C:.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.text.globl main main: la $s0, A la $s1, B la $s2, C li $s3, 10 li $t0, 0# using $t0 as i LOOP:addi $t0, $t0, 1# i ++ bne $t0, $s3, LOOP# go back if not yet 10 times done:li $v0,10 syscall

. data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 B:.word 90, 2, 93, 66, 8, 120, 121,11, 33, 9 C:.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.text.globl main main: la $s0, A la $s1, B la $s2, C li $s3, 10 li $t0, 0# using $t0 as i LOOP:sll $t4, $t0, 2# $t4 = i * 4 add $t5, $t4,$s0# $t5 will have the address of A[i] lw $t1, 0($t5)# $t1 has A[i] add $t6, $t4,$s1# $t6 will have the address of B[i] lw $t2, 0($t6)# $t2 has B[i] addi $t0, $t0, 1# i ++ bne $t0, $s3, LOOP# go back if not yet 10 times done:li $v0,10 syscall

. data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 B:.word 90, 2, 93, 66, 8, 120, 121,11, 33, 9 C:.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.text.globl main main: la $s0, A la $s1, B la $s2, C li $s3, 10 li $t0, 0# using $t0 as i LOOP:sll $t4, $t0, 2# $t4 = i * 4 add $t5, $t4,$s0# $t5 will have the address of A[i] lw $t1, 0($t5)# $t1 has A[i] add $t6, $t4,$s1# $t6 will have the address of B[i] lw $t2, 0($t6)# $t2 has B[i] slt $t5, $t1, $t2# set $t5 to be 1 if A[i] < B[i] beq $t5, $0, L1# if $t5 == 0, goto L1. in this case, A[i] >= B[i] ori $t8, $t1, 0# setting $t8 to be A[i] j L2# always remember to jump in an if else! L1: ori $t8, $t2, 0# setting $t8 to be B[i] L2: addi $t0, $t0, 1# i ++ bne $t0, $s3, LOOP# go back if not yet 10 times done:li $v0,10 syscall

. data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 B:.word 90, 2, 93, 66, 8, 120, 121,11, 33, 9 C:.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.text.globl main main: la $s0, A la $s1, B la $s2, C li $s3, 10 li $t0, 0# using $t0 as i LOOP:sll $t4, $t0, 2# $t4 = i * 4 add $t5, $t4,$s0# $t5 will have the address of A[i] lw $t1, 0($t5)# $t1 has A[i] add $t6, $t4,$s1# $t6 will have the address of B[i] lw $t2, 0($t6)# $t2 has B[i] slt $t5, $t1, $t2# set $t5 to be 1 if A[i] < B[i] beq $t5, $0, L1# if $t5 == 0, goto L1. in this case, A[i] >= B[i] ori $t8, $t1, 0# setting $t8 to be A[i] j L2# always remember to jump in an if else! L1: ori $t8, $t2, 0# setting $t8 to be B[i] L2: add $t6, $t4, $s2# now $t6 has the address of C[i] sw $t8, 0($t6)# now C[i] has the minimum of A[i] and B[i] addi $t0, $t0, 1# i ++ bne $t0, $s3, LOOP# go back if not yet 10 times done:li $v0,10 syscall

Exercise 2 4/17/2015week04-3.ppt9 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 A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19.text.globl main main: la $s7, A# getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1:addi $s0, $s0, 1# i = i + 1 bne $s0, $s6, LOOP1# if i != N-1, outer loop again done:li $v0,10 syscall Getting the first loop done

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

.data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19.text.globl main main: la $s7, A# getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1:li $s1, 0# j = 0 LOOP2:sll $t0, $s1, 2# $t0 = j * 4 add $t0, $t0, $s7# $t0 is the address of A[j] lw $t1, 0($t0)# $t1 = A[j] lw $t2, 4($t0)# $t2 = A[j+1] addi $s1, $s1, 1# j = j + 1 sub $t7, $s6, $s0# $t7 will get N-1-i bne $s1, $t7, LOOP2# if j != N-1-i, inner loop again addi $s0, $s0, 1# i = i + 1 bne $s0, $s6, LOOP1# if i != N-1, outer loop again done:li $v0,10 syscall Adding the code to read the elements A[j] and A[j+1]

.data A:.word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19.text.globl main main: la $s7, A# getting the address li $s6, 9 # N-1 li $s0, 0 # i = 0 LOOP1:li $s1, 0# j = 0 LOOP2:sll $t0, $s1, 2# $t0 = j * 4 add $t0, $t0, $s7# $t0 is the address of A[j] lw $t1, 0($t0)# $t1 = A[j] lw $t2, 4($t0)# $t2 = A[j+1] bgt $t1, $t2, L1# if A[j] > A[j+1] goto L1, bypass the swapping sw $t1,4($t0)# do the swap sw $t2,0($t0)# do the swap L1: addi $s1, $s1, 1# j = j + 1 sub $t7, $s6, $s0# $t7 will get N-1-i bne $s1, $t7, LOOP2# if j != N-1-i, inner loop again addi $s0, $s0, 1# i = i + 1 bne $s0, $s6, LOOP1# if i != N-1, outer loop again done: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. We have seen some: li $s0, 0 # load immediate number, often mapped to ori. la $s7, A# load the address of label A into $s7 bgt $t1, $t2, L1 # branch if $t1 is greater than $t2. ``blt’’ also exits.

In-class exercise -- Loop