MIPS Assembly.

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

Lecturer PSOE Dan Garcia
Goal: Write Programs in Assembly
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
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.
CS/COE0447 Computer Organization & Assembly Language
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.
Chapter 2 Instructions: Language of the Computer
Chapter 2.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
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.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
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.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
CSCI 136 Lab 1: 135 Review.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
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.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
CDA 3101 Spring 2016 Introduction to Computer Organization
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
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 Instruction Set Advantages
COMPUTER ARCHITECTURE & OPERATIONS I
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
Computer Organization and Design Instruction Sets - 2
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Assembly Programming using MIPS R3000 CPU
Instructions for Making Decisions
Lecture 4: MIPS Instruction Set
MPIS Instructions Functionalities of instructions Instruction format
MISP Assembly.
Computer Architecture & Operations I
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
MIPS Assembly.
Computer Architecture
Flow of Control -- Conditional branch instructions
3.
Assembly Programming using MIPS R3000 CPU
Flow of Control -- Conditional branch instructions
MIPS Coding Continued.
MIPS assembly.
7/6/
MIPS instructions.
Presentation transcript:

MIPS Assembly

Review A computer has processor, memory, and IO devices. The processor stores values in registers, and modifies values by sending them to the ALU. Memory is where the computer stores a large number of values. Every byte can be accessed by specifying a unique address. The address goes from 0 to 0xffffffff in MIPS. In MIPS we mainly work with word which is 4 bytes. MIPS instructions learned: add, sub. lw, sw.

Constant or Immediate Operands 4/18/2019 Constant or Immediate Operands Many times we use a constant in an operation For example, i++, i--, i += 4, and so on Since constant operands occur frequently, we should include constants inside arithmetic operations so that they are much faster MIPS has an add instruction that allows one operand to be a constant The constant must be in 16 bits, as a signed integer in 2’s complement format addi $s1, $s2, 100 # $s1 = $s2 + 100 CDA3100 4/18/2019 CDA3100

4/18/2019 Logical Operations Often we need to operate on bit fields within a word. Which allow us to pack and unpack bits into words and perform logical operations such as logical and, logical or, and logical negation CDA3100 4/18/2019 CDA3100

Bit-wise AND Apply AND bit by bit 4/18/2019 Bit-wise AND Apply AND bit by bit The resulting bit is 1 if both of the input bits are 1 and zero otherwise and $t2, $t0, $t1 There is also a version of AND with an immediate andi $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number CDA3100 4/18/2019 CDA3100

Bit-wise OR Apply OR bit by bit 4/18/2019 Bit-wise OR Apply OR bit by bit The resulting bit is 1 if at least one of the input bits is 1 and zero otherwise or $t2, $t0, $t1 There is also a version of OR with an immediate ori $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number CDA3100 4/18/2019 CDA3100

Bit-wise XOR Apply XOR bit by bit 4/18/2019 Bit-wise XOR Apply XOR bit by bit The resulting bit is 1 if two bits are different xor $t2, $t0, $t1 There is also a version of OR with an immediate xori $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number CDA3100 4/18/2019 CDA3100

4/18/2019 NOR Since NOT takes one operand and results in one operand, it is not included in MIPS as an instruction Because in MIPS each arithmetic operation takes exactly three operands Instead, NOR is included The resulting bit is 0 if at least one of the input bits is 1 nor $t2, $t0, $t1 How to implement NOT using NOR? Using $zero as one of the input operands It is included in MIPS as a pseudoinstruction CDA3100 4/18/2019 CDA3100

Exercise 1 After learnt these instructions, how can we load an integer value (like 100) into a register ($t0)?

Exercise 1 After learnt these instructions, how can we load an integer value (like 100) into a register ($t0)? addi $t0, $zero, 100 ori $t0, $zero, 80 Which should we prefer? ori. Because it is simpler than add. Simpler means less time, less power consumption.

4/18/2019 Shifts Shift instructions move all the bits in a word to the left or to the right Shift left logical (sll) move all the bits to the left by the specified number of bits sll $t2, $t0, 2 Shift right logical (srl) move all the bits to the right srl $t2, $t0, 2 Filling the emptied bits with 0’s CDA3100 4/18/2019 CDA3100

Example Suppose register $s0 ($16) is 9ten 4/18/2019 Example Suppose register $s0 ($16) is 9ten What do we have in $t2 ($10) after 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 CDA3100 4/18/2019 CDA3100

Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after 4/18/2019 Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after The value is 144ten = 9ten  24 In general, shifting left by i bits gives the same result as multiplying by 2i 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 CDA3100 4/18/2019 CDA3100

Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after 4/18/2019 Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after The value is NOT 9ten  228 Note that overflow happens this time (for signed numbers) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 CDA3100 4/18/2019 CDA3100

Instructions for Making Decisions 4/18/2019 Instructions for Making Decisions A distinctive feature of programs is that they can make different decisions based on the input data CDA3100 4/18/2019 CDA3100

Instruction beq (branch if equal) 4/18/2019 Instruction beq (branch if equal) To support decision making, MIPS has two conditional branch instructions, similar to an “if” statement with a goto In C, it is equivalent to Note that L1 is a label and we are comparing values in register1 and register2 Label is an address of an instruction CDA3100 4/18/2019 CDA3100

4/18/2019 Instruction bne Similarly, bne (branch not equal) means go to the statement labeled with L1 if the value in register1 does not equal to the value in regster2 Equivalent to CDA3100 4/18/2019 CDA3100

4/18/2019 Instruction j (jump) MIPS has also an unconditional branch, equivalent to goto in C Jump to the instruction labeled with L1 CDA3100 4/18/2019 CDA3100

Compiling if-then-else 4/18/2019 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? CDA3100 4/18/2019 CDA3100

Compiling if-then-else 4/18/2019 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? CDA3100 4/18/2019 CDA3100

Compiling if-then-else 4/18/2019 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? CDA3100 4/18/2019 CDA3100

MIPS Assembly for if-then-else 4/18/2019 MIPS Assembly for if-then-else Now it is straightforward to translate the C program into MIPS assembly CDA3100 4/18/2019 CDA3100