Chapter 2. Instructions:

Similar documents
Chapter 3. Instructions:

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2. Instruction Set Architecture (ISA)

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

CS222: MIPS Instruction Set

Chapter 2: Instructions:

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

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

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

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

Computer Architecture

Topic Notes: MIPS Instruction Set Architecture

All instructions have 3 operands Operand order is fixed (destination first)

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

ECE369. Chapter 2 ECE369

Chapter 2A Instructions: Language of the Computer

Lecture 4: MIPS Instruction Set

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

Levels of Programming. Registers

Instructions: Language of the Computer

ECE232: Hardware Organization and Design

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

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

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

MIPS%Assembly% E155%

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

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

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

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

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

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Lecture 6 Decision + Shift + I/O

Instructions: Assembly Language

IC220 SlideSet #2: Instructions (Chapter 2)

CS3350B Computer Architecture MIPS Instruction Representation

Lecture 5: Procedure Calls

Computer Architecture

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

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

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

ECE 154A Introduction to. Fall 2012

ECE 30 Introduction to Computer Engineering

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

COMPUTER ORGANIZATION AND DESIGN

CS3350B Computer Architecture MIPS Introduction

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

CS3350B Computer Architecture

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

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

CENG3420 Lecture 03 Review

Processor design - MIPS

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

MIPS Hello World. MIPS Assembly 1. # PROGRAM: Hello, World! # Data declaration section. out_string:.asciiz "\nhello, World!\n"

Chapter 2. Instructions: Language of the Computer

Instructions: Language of the Computer

Instruction Set Design and Architecture

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

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

CENG3420 L03: Instruction Set Architecture

Computer Architecture. The Language of the Machine

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

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

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

Course Administration

Thomas Polzer Institut für Technische Informatik

Unsigned Binary Integers

Unsigned Binary Integers

Computer Architecture. Lecture 2 : Instructions

MIPS Memory Access Instructions

Architecture I. Computer Systems Laboratory Sungkyunkwan University

MIPS Instruction Set Architecture (2)

Computer Architecture. MIPS Instruction Set Architecture

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

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Programming the processor

Computer Organization MIPS ISA

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

MACHINE LANGUAGE. To work with the machine, we need a translator.

Reduced Instruction Set Computer (RISC)

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

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

CS/COE1541: Introduction to Computer Architecture

(Refer Slide Time: 1:40)

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Lectures 3-4: MIPS instructions

Reduced Instruction Set Computer (RISC)

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Transcription:

Chapter 2 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions We ll be working with the MIPS instruction set architecture similar to other architectures developed since the 1980's used by NEC, Nintendo, Silicon Graphics, Sony Design goals: maximize performance and minimize cost, reduce design time 2

MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B + C MIPS code: add $s0, $s1, $s2 (associated with variables by compiler) 3 MIPS arithmetic Design Principle: simplicity favors regularity. Why? Of course this complicates some things... C code: A = B + C + D; E = F - A; MIPS code: add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0 Operands must be registers, only 32 registers provided Design Principle: smaller is faster. Why? 4

Registers vs. Memory Arithmetic instructions operands must be registers, only 32 registers provided Compiler associates variables with registers What about programs with lots of variables Control Input Memory Datapath Output Processor I/O 5 Memory Organization Viewed as a large, single-dimension array, with an address. A memory address is an index into the array "Byte addressing" means that the index points to a byte of memory. 0 1 2 3 4 5 6... 6

Memory Organization Bytes are nice, but most data items use larger "words" For MIPS, a word is 32 bits or 4 bytes. 0 4 8 12 32 bits of data 32 bits of data 32 bits of data 32 bits of data Registers hold 32 bits of data... 2 32 bytes with byte addresses from 0 to 2 32-1 2 30 words with byte addresses 0, 4, 8,... 2 32-4 Words are aligned i.e., what are the least 2 significant bits of a word address? 7 Instructions Load and store instructions Example: C code: MIPS code: A[8] = h + A[8]; lw $t0, 32($s3) add $t0, $s2, $t0 sw $t0, 32($s3) Store word has destination last Remember arithmetic operands are registers, not memory! 8

Logical Operations Need instructions for operating on the individual bits of a word For example, since ASCII characters are stored in 8 bits (one byte), we need operations that allow us to examine one byte within a word Also, high-level languages such as C and Java support logical operations such as AND, OR, and SHIFT MIPS supports bit-by-bit AND, OR, and NOT operations AND and OR or NOT nor These instructions are similar to arithmetic instructions in their format and usage For Example, and $t1,$t2,$t3 # reg $t1 = reg $t2 & reg $t3 or $t1,$t2, $t3 # reg $t1 = reg $t2 reg $t3 9 Shift instructions Shift operations move all the bits in a word to the right or left, filling the emptied bits with 0s For example, if register $s0 contained 0000 0000 0000 0000 0000 0000 0000 1101 (= 9 ten ) then shifting it left by 4 bits would give us 0000 0000 0000 0000 0000 0000 1101 0000 (= 144 ten ) This is accomplished by the instruction sll (shift left logical) sll $t1,$s0,4 # reg $t1 = reg $s0 << 4 Similarly srl (shift right logical) is used to shift a word to the right sll and srl can be used to multiply and divide an integer by 2 respectively 10

So far we ve learned: MIPS loading words but addressing bytes arithmetic and logical operations on registers only Instruction Meaning add $s1, $s2, $s3 $s1 = $s2 + $s3 sub $s1, $s2, $s3 $s1 = $s2 $s3 lw $s1, 100($s2) $s1 = Memory[$s2+100] sw $s1, 100($s2) Memory[$s2+100] = $s1 and $t1,$t2,$t3 $t1 = $t2 & $t3 or $t1,$t2, $t3 $t1 = $t2 $t3 sll $t1,$t2,4 $t1 = $t2 << 4 bits srl $t1,$t2,4 $t1 = $t2 >> 4 bits 11 Stored Program Concept Instructions are bits Programs are stored in memory to be read or written just like data Processor Memory memory for data, programs, compilers, editors, etc. Fetch & Execute Cycle Instructions are fetched and put into a special register Bits in the register "control" the subsequent actions Fetch the next instruction and continue 12

Control Decision making instructions alter the control flow, i.e., change the "next" instruction to be executed MIPS conditional branch instructions: bne $t0, $t1, Label beq $t0, $t1, Label Example: if (i==j) h = i + j; bne $s0, $s1, Label add $s3, $s0, $s1 Label:... 13 Control MIPS unconditional branch instructions: j label Example: if (i!=j) beq $s4, $s5, Lab1 h=i+j; add $s3, $s4, $s5 else j Lab2 h=i-j; Lab1: sub $s3, $s4, $s5 Lab2:... Can you build a simple for loop? 14

Control Flow We have: beq, bne, what about Branch-if-less-than? New instruction: if $s1 < $s2 then $t0 = 1 slt $t0, $s1, $s2 else $t0 = 0 Can use this instruction to build "blt $s1, $s2, Label" can now build general control structures Note that the assembler needs a register to do this, there are policy of use conventions for registers 15 Policy of Use Conventions Name Register number Usage $zero 0 the constant value 0 $v0-$v1 2-3 values for results and expression evaluation $a0-$a3 4-7 arguments $t0-$t7 8-15 temporaries $s0-$s7 16-23 saved $t8-$t9 24-25 more temporaries $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address 16

Constants Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory and load them. create hard-wired registers (like $zero) for constants like one. MIPS Instructions: addi $29, $29, 4 slti $8, $18, 10 andi $29, $29, 6 ori $29, $29, 4 17