Lecture 6 Decision + Shift + I/O

Similar documents
CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS61C : Machine Structures

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

CS61C : Machine Structures

CS61C : Machine Structures

Bonus slides. Garcia, Spring 2014 UCB. CS61C L11 Introduction to MIPS : Procedures II & Logical Ops (18)

Chapter 2. Instructions:

And in Review. Register Conventions (2/4) saved. Register Conventions (1/4) Register Conventions (4/4) Register Conventions (3/4) volatile

F. Appendix 6 MIPS Instruction Reference

We will study the MIPS assembly language as an exemplar of the concept.

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

MIPS Instruction Reference

UCB CS61C : Machine Structures

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

CS3350B Computer Architecture MIPS Instruction Representation

MIPS Coding Continued

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

ú There are CONVENTIONS when calling procedures! Stack main ()! { a(0);! }! void a (int m)! frame" Garcia, Spring 2013 UCB printf() (y==?

Computer Architecture

Lecture 4: MIPS Instruction Set

ECE232: Hardware Organization and Design

COMP MIPS instructions 2 Feb. 8, f = g + h i;

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

LAB B Translating Code to Assembly

Examples of branch instructions

Midterm. CS64 Spring Midterm Exam

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Mips Code Examples Peter Rounce

ECE 30 Introduction to Computer Engineering

Flow of Control -- Conditional branch instructions

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2A Instructions: Language of the Computer

Assembly Programming

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Computer Architecture

Outline. Homework. Assembly Language. Instructions. Instruction Set Architectures. Csci 136 Computer Architecture II MIPS Instruction Set Architecture

Topic Notes: MIPS Instruction Set Architecture

CDA3100 Midterm Exam, Summer 2013

Numbers: positional notation. CS61C Machine Structures. Faux Midterm Review Jaein Jeong Cheng Tien Ee. www-inst.eecs.berkeley.

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Unsigned Binary Integers

Unsigned Binary Integers

MIPS%Assembly% E155%

ECE Exam I February 19 th, :00 pm 4:25pm

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

Course Administration

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

CSc 256 Midterm (green) Fall 2018

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

Introduction to MIPS Processor

CS61C : Machine Structures

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

TSK3000A - Generic Instructions

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Lecture 5: Procedure Calls

CS 61c: Great Ideas in Computer Architecture

ECE 15B Computer Organization Spring 2010

MIPS Assembly Programming

ECE 154A Introduction to. Fall 2012

ECE260: Fundamentals of Computer Engineering

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Computer Architecture. Lecture 2 : Instructions

CS61C : Machine Structures

Instructions: Assembly Language

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Lectures 3-4: MIPS instructions

CSc 256 Midterm 1 Fall 2011

MIPS Instruction Set Architecture (2)

Compiling Techniques

RISC-V Assembly and Binary Notation

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

ECE260: Fundamentals of Computer Engineering

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Q1: /30 Q2: /25 Q3: /45. Total: /100

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Lecture 9: Disassembly

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Chapter 3. Instructions:

UCB CS61C : Machine Structures

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

EEC 581 Computer Architecture Lecture 1 Review MIPS

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

CENG3420 Lecture 03 Review

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Transcription:

Lecture 6 Decision + Shift + I/O

Instructions so far MIPS C Program add, sub, addi, multi, div lw $t0,12($s0) sw $t0, 12($s0) beq $s0, $s1, L1 bne $s0, $s1, L1 j L1 (unconditional branch) slt reg1,reg2,reg3 a=b+c, a=b-c, a=b+10, a=b*c, a=b/c t= A[3] A[3]=t If (a==b) go to L1 If (a!=b) go to L1 goto L1 if (reg2 < reg3) reg1 = 1; else reg1 = 0;

Optional Individual Submission for Today s Quiz Turnin under quiz2 In the program, include your name/perm number By 11:59PM Tonight

Shift Instructions TODAY S FOCUS

Bitwise Operations Up until now, we ve done arithmetic (add, sub,addi ), memory access (lw and sw), and branches and jumps. All of these instructions view contents of register as a single quantity (such as a signed or unsigned integer) New Perspective: View contents of register as 32 individual bits rather than as a single 32-bit number

Bitwise Operations Since registers are composed of 32 bits, we may want to access individual bits (or groups of bits) rather than the whole. Introduce two new classes of instructions: Logical Operators Shift Instructions

Logical Operators Two basic logical operators: AND: outputs 1 only if both inputs are 1 OR: outputs 1 if at least one input is 1 In general, can define them to accept >2 inputs, but in the case of MIPS assembly, both of these accept exactly 2 inputs and produce 1 output Again, rigid syntax, simpler hardware

Logical Operators Truth Table: standard table listing all possible combinations of inputs and resultant output for each Truth Table for AND and OR A B A AND B A OR B 0 0 0 1 1 0 1 1 0! 0! 0! 1! 0! 1! 1! 1!

Logical Operators Logical Instruction Syntax: 1 2,3,4 where 1) operation name 2) register that will receive value 3) first operand (register) 4) second operand (register) or immediate (numerical constant)

Logical Operators Instruction Names: and, or: Both of these expect the third argument to be a register andi, ori: Both of these expect the third argument to be an immediate MIPS Logical Operators are all bitwise, meaning that bit n of the output is produced by the respective bit n s of the inputs, bit 1 by the bit 1 s, etc.

Uses for Logical Operators Note that anding a bit with 0 produces a 0 at the output while anding a bit with 1 produces the original bit. This can be used to create a mask. Example: 1011 0110 1010 0100 0011 1101 1001 1010 0000 0000 0000 0000 0000 1111 1111 1111 The result of anding these: 0000 0000 0000 0000 0000 1101 1001 1010 mask last 12 bits!

Uses for Logical Operators The second bitstring in the example is called a mask. It is used to isolate the rightmost 12 bits of the first bitstring by masking out the rest of the string (e.g. setting it to all 0s). The and operator can also be used to set certain portions of a bitstring to 0s, while leaving the rest alone. In particular, if the first bitstring in the above example were in $t0, then the following instruction would mask the last 12 bits: andi $t0,$t0,0x0fff

Uses for Logical Operators Similarly, note that oring a bit with 1 produces a 1 at the output while oring a bit with 0 produces the original bit. This can be used to force certain bits of a string to 1s. For example, if $t0 contains 0x12345678, then after this instruction: ori $t0, $t0, 0xFFFF $t0 contains 0x1234FFFF (e.g. the high-order 16 bits are untouched, while the low-order 16 bits are forced to 1s).

Exercises $t0 holds the value of 0x1100FF What is the result of $t0 in each step: and $t0, $t0, $t0 andi $t0, $t0, 0xFF and $t0, $t0, $zero ori $t0, $t0, 0xFFFF or $t0, $t0, $zero ori $t0, $t0, 0x1001

Shift Instructions Move (shift) all the bits in a word to the left or right by a number of bits. Example: shift right by 8 bits 0001 0010 0011 0100 0101 0110 0111 1000 0000 0000 0001 0010 0011 0100 0101 0110 Example: shift left by 8 bits 0001 0010 0011 0100 0101 0110 0111 1000 0011 0100 0101 0110 0111 1000 0000 0000

Shift Instructions Shift Instruction Syntax: 1 2,3,4 where 1) operation name 2) register that will receive value 3) first operand (register) 4) shift amount (constant <= 32)

Shift Instructions MIPS shift instructions: 1. sll (shift left logical): shifts left and fills emptied bits with 0s 2. srl (shift right logical): shifts right and fills emptied bits with 0s 3. sra (shift right arithmetic): shifts right and fills emptied bits by sign extending

Shift Instructions Example: shift right arithmetic by 8 bits 0001 0010 0011 0100 0101 0110 0111 1000 0000 0000 0001 0010 0011 0100 0101 0110 Example: shift right arithmetic by 8 bits 1001 0010 0011 0100 0101 0110 0111 1000 1111 1111 1001 0010 0011 0100 0101 0110

Uses for Shift Instructions Suppose we want to isolate byte 0 (rightmost 8 bits) of a word in $t0. Simply use: andi $t0,$t0,0x00ff Suppose we want to isolate byte 1 (bit 15 to bit 8) of a word in $t0. We can use: andi $t0,$t0,0xff00 but then we still need to shift to the right by 8 bits...

Uses for Shift Instructions Could use instead: sll $t0,$t0,16 srl $t0,$t0,24 0001 0010 0011 0100 0101 0110 0111 1000 0101 0110 0111 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0101 0110

Uses for Shift Instructions In binary: Multiplying by 2 is same as shifting left by 1: 11 2 x 10 2 = 110 2 1010 2 x 10 2 = 10100 2 Multiplying by 4 is same as shifting left by 2: 11 2 x 100 2 = 1100 2 1010 2 x 100 2 = 101000 2 Multiplying by 2 n is same as shifting left by n

Uses for Shift Instructions Since shifting is faster than multiplication, a good compiler usually notices when C code multiplies by a power of 2 and compiles it to a shift instruction: a *= 8; (in C) would compile to: sll $s0,$s0,3 (in MIPS) Likewise, shift right to divide by powers of 2 remember to use sra

MIPS Native Instructions Instructions that have direct hardware implementation, implement in 1 cycle As opposed to pseudo instructions which are translated into multiple native instructions Native: Add, addi, add, sub, lw, sw, and, andi, or, ori, slt, sll, srl, beq, bne, j, jr, jal Pseudo: Multi, div, li, bge, ble

A Short Summary Logical and Shift Instructions Operate on bits individually, unlike arithmetic, which operate on entire word. Use to isolate fields, either by masking or by shifting back and forth. Use shift left logical, sll, for multiplication by powers of 2 Use shift right arithmetic, sra, for division by powers of 2. New Instructions: and,andi, or,ori, sll,srl,sra

Assembly Program of the Day Exit the program via system call # Daniel J. Ellard -- 02/21/94 # add.asm-- A program that computes the sum of 1 and 2, # leaving the result in register $t0. # Registers used: # t0 - used to hold the result. # t1 - used to hold the constant 1. # v0 - syscall parameter.. text main: # SPIM starts execution at main. li $t1, 1 # load 1 into $t1. add $t0, $t1, 2 # compute the sum of $t1 and 2, and # put it into $t0. li $v0, 10 # syscall code 10 is for exit. syscall # make the syscall.