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.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CENG 311 Decisions in C/Assembly Language
Goal: Write Programs in Assembly
4.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
Branches Two branch instructions:
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
1 CDA 3101 Discussion Section 03.  Problem The following problems deal with translating from C to MIPS. Assume that the variables f, g, h, i and.
The University of Adelaide, School of Computer Science
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.
Chapter 2 Instructions: Language of the Computer
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
MIPS Function Continued
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
ITEC 352 Lecture 16 ISA(7). Review Exam / Questions? Conditional codes, how important are they? How important are comments in assembly? What are the benefits.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CS2100 Computer Organisation
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
Decision Making.
Instructions for Making Decisions
The University of Adelaide, School of Computer Science
MIPS coding.
MIPS Procedures.
Lecture 4: MIPS Instruction Set
MISP Assembly.
How to represent signed integers
Solutions Chapter 2.
ECE232: Hardware Organization and Design
MIPS coding.
MIPS coding.
MIPS Coding.
The University of Adelaide, School of Computer Science
MIPS Assembly.
MIPS Functions.
MIPS Coding.
MIPS Assembly.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
7/6/
MIPS Functions.
MIPS Processor.
MIPS instructions.
Conditional Branching (beq)
Presentation transcript:

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  The instructions are also stored sequentially in the memory. Executing the code is to load then execute the instructions one by one, unless we encounter a branch condition.

Review  Label: A label is associated with exactly one instruction. We can understand it as the address of the instruction in the memory. Go to a label means that fetch that instruction from the memory and execute it.  A label in MIPS looks like L1: add $t0, $t1, $t2

Review  We talked about the if-else in MIPS.  When we want to do if ($t0 == $t1) $t0 = $t1 + $t2; else $t0 = $t1 - $t2;  One of the correct ways is beq $t0, $t1, L1 sub $t0, $t1, $t2 j exit L1: add $t0, $t1, $t2 exit:

Review  Suppose $t0, $t1, $t2 are storing 1,2,3, respectively. What will the values in $t0 be after we come to these instructions? beq $t0, $t1, L1 sub $t0, $t1, $t2 L1: add $t0, $t1, $t2 exit:

Exercise 2  How to implement this with only the instructions we learnt? if ($t1 > $t2) $t0 = $t1; else $t0 = $t2;

Exercise 2 # if ($t1 > $t2) $t0 = $t1; # else $t0 = $t2; sub $t3, $t1, $t2 srl $t3, $t3, 31 bne $t3, $zero, L1 ori $t0, $t1, 0 j L2 L1: ori $t0, $t2, 0 L2:

slt, slti  slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0.  “Set Less Than.”  slti $t3, $t1, 100 – set $t3 to be 1 if $t1 < 100 ; else clear $t3 to be 0.  Using slt, the code is simpler.

Using slt slt $t3, $t1, $t2 bne $t3, $zero, L21 ori $t0, $t1, 0 j L22 L21: ori $t0, $t2, 0 L22:

Some Comments  Being able to write if-else, we can have all other fancy things like for loop, while loop….  That is why we do not have an instruction for the for loop or while loop, but we build it from the if-else.

Compiling a while loop in C 4/13/2015 week04-3.ppt 11  How to translate the following to MIPS assembly?  We first translate into a C program using if and goto

Compiling a while loop in C 4/13/2015 week04-3.ppt 12  Assume that i and k correspond to registers $s3 and $s5 and starting address of array save is in $s6